1
votes

I'm trying to create nodes using SDN 3.0.2 and Neo4j 2.0.1

Here is how I'm doing :

query = "MATCH (root:Date) " +
    "CREATE UNIQUE (root)<-[:`"+year+"`]-(y:Year {value:'"+year+"Y"+"'})" +
    "<-[:`"+month+"`]-(m:Month {value:'"+year+"Y"+month+"M"+"'})" +
        "<-[:`"+day+"`]-(d:Day {value:'"+year+"Y"+month+"M"+day+"D"+"'}) " +
    "RETURN d";
Iterable<Day> days = template.query(query, map).to(Day.class);
Transaction tx = template.getGraphDatabaseService().beginTx();
Set<Day> result = IteratorUtil.asSet(days);
tx.close();

Executing this way, I'm getting java.lang.IllegalStateException: No primary SDN label exists .. (i.e one with starting with _) For the Set<Day> result = IteratorUtil.asSet(days)

While It works fine if I delete Set<Day> result = IteratorUtil.asSet(days) But I actually need to return the result which is a unique Day entity.

Am I missing something?

Here's the Day POJO:

@NodeEntity
@TypeAlias(value="Day")
public class Day implements Serializable {
    private static final long serialVersionUID = 1L;
    @GraphId 
    private Long nodeId;
    @Indexed(unique=true)
    private String id;

    //@Indexed(indexType=IndexType.FULLTEXT, indexName = "days")
    private String value;

    @RelatedTo(type="NEXT_DAY", direction = Direction.BOTH)
    private Day next;

    private Month month;

        //Other relationships to different entities
        //Getters & setters
        //Empty & with params constructors

}
1
Can you share your Day POJO? - BtySgtMajor
I've edited the post to add it - Monta
Also your code seems to miss tx.success() - Michael Hunger
and for at least the property values you should use parameters. - Michael Hunger

1 Answers

1
votes

I had to add _Label in the cypher query:

query = "MATCH (root:Date) " +
    "CREATE UNIQUE (root)<-[:`"+year+"`]-(y:Year:_Year {value:'"+year+"Y"+"'})" +
    "<-[:`"+month+"`]-(m:Month:_Month {value:'"+year+"Y"+month+"M"+"'})" +
        "<-[:`"+day+"`]-(d:Day:_Day {value:'"+year+"Y"+month+"M"+day+"D"+"'}) " +
    "RETURN d";