1
votes

I am using the newest Spring Data for Neo4j. In this projects i have different groups which are reachable over the url /group/{id}/project which should return a list of all projects the user has access to. This stuff works fine, but if the user enters a real big number as groupId which does not exist in the database I got a

org.neo4j.graphdb.NotFoundException: Node 400 not found

My query looks like

@Query("START a=node({userId}), b=node({groupId}) match a-[:user_belongs_to]-b return b")
GroupEntity getGroup(@Param("userId") Long userId, @Param("groupId") Long groupId);

Even if I use the method findOne() from the GraphRepository interface I got this exception.

So is it possible to tell SDN instead of throwing this exception returning null? Or does i have to catch every possible runtime exception?

I want to throw exceptions by my own i.e. NoSuchGroup, NoSuchUser..

I am using SDN 3.3.0.Release.

Thank you

1

1 Answers

0
votes

Which is to be expected, if the node is not found.

You should not use the Neo4j node-id for this but a custom id that you create an manage when you create the Group.

e.g.

@NodeEntity
class Group {

   @GraphId Long id;
   @Indexed int groupId;

   @RelatedTo(type="user_belongs_to",direction=INCOMING)
   Set<User> users;

}

interface GroupRepository extends GraphRepository<Group> {
   @Query("match (a:User)-[:user_belongs_to]-(b:Group) where a.userId = {userId} and b.groupId={groupId} return b")
   GroupEntity getGroup(@Param("userId") Long userId, @Param("groupId") Long groupId);

   // generated finder method
   GroupEntity findByGroupIdAndUsersUserId(@Param("groupId") Long groupId, @Param("userId") Long userId);
}