Prabhat
Prabhat

Reputation: 840

Spring Data Neo4j - '__type__' property not found for NodeImpl#0

I am trying to play with neo4j with the help of spring data in my java application. Currently i'm facing a strange problem. Following is the scenario.

I have:
1. Two UserNode, say A and B, where "UserNode" is java @NodeEntity class. 
2. A @RelationshipEntity "RequestedTo" which is again a java class. 
3. A relationship "A RequestedTo B" which is directed towards B.

Now when i try to fetch all the UserNode which have a RequestedTo relationship directed towards B i get following exception

Caused by: org.neo4j.graphdb.NotFoundException: '__type__' property not found for NodeImpl#0.
    at org.neo4j.kernel.impl.core.Primitive.newPropertyNotFoundException(Primitive.java:184)
    at org.neo4j.kernel.impl.core.Primitive.getProperty(Primitive.java:179)
    at org.neo4j.kernel.impl.core.NodeImpl.getProperty(NodeImpl.java:52)
    at org.neo4j.kernel.impl.core.NodeProxy.getProperty(NodeProxy.java:155)
    at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexingTypeRepresentationStrategy.readAliasFrom(AbstractIndexingTypeRepresentationStrategy.java:106)

Here i do following query to neo4j using GraphRepository interface provided in Spring.

START user=node:searchByMemberID(memberID={0}) , member=node(*), root = node(0) MATCH user<-[r:RequestedTo]-member WHERE member <> root RETURN member

Also, when i fire this query in neoclipse i can see that there is no "type" property on UserNode in result. But when i try this query in neo4j browser console i can see the "type" property coming in the result set.

Upvotes: 3

Views: 1044

Answers (3)

Gr&#233;goire C
Gr&#233;goire C

Reputation: 1381

I had the same error as the OP:

'__type__' property not found for NodeImpl#0

and solved it by checking the existence of the __type__ property using the has keyword.

More explicitly, this request raises the error:

@Query(value = "start n=node(*) where not (n)-[:hasParent]->() return n")
Set<MyNodeType> findRootNodes();

but this request works:

@Query(value = "start n=node(*) where has(n.__type__) and not (n)-[:hasParent]->() return n")
Set<MyNodeType> findRootNodes();

Hope this will help someone.

Upvotes: 0

Michael Hunger
Michael Hunger

Reputation: 41676

You don't need to specify member in start, cypher takes care of that itself. After all local queries from a single or few starting points is what graph databases is about:

START user=node:searchByMemberID(memberID={0})
MATCH user<-[r:RequestedTo]-member 
RETURN member

Upvotes: 1

jarandaf
jarandaf

Reputation: 4427

I just played a little bit with Neo4j but try this instead:

START user=node:searchByMemberID(memberID={0}) , member=node(*)
MATCH user<-[r:RequestedTo]-member 
WHERE id(member) <> 0 
RETURN member

Upvotes: 1

Related Questions