0

I am using SDN4 and facing the issue of previous relationships getting deleted on adding new different ones. Here is my scenario,

Step 1 Create a node with some relationships using Relationship entities. save the relationship entity.

Step 2 get the node based on some properties using Spring Repository and Cypher and add new different relationships. Here is my fetch API:

@Component("productRepository")
public interface ProductRepository extends GraphRepository<Product>{
   @Query("MATCH (c:Product {uuid:{0}}) RETURN c")
   Product findByUuid(String uuid);
}

save the relationship entity

after doing this, the relationships added in step 1 are lost, but those in step 2 persist.

on doing some debugging, i can see that the Node entities returned by a fetch using Cypher and Spring Repository has null value for relationship entity.

Note: If I do not do step 2, then relations in step 1 are reflected correctly.

Could someone please let me know If i am missing something or if this is an issue.I am not seeing a way to specify depth in this case unless this is somewhere in the cypher.

Gaurav Abbi
  • 645
  • 9
  • 23

3 Answers3

2

The depth parameter on a @Query is not supported. The options you have at this point are -

a. To reload the Product returned by the @Query to the depth you require using the repository findOne(id,depth), or the Neo4jTemplate.load(type,id,depth)

b. If you can translate your @Query to a set of org.neo4j.ogm.cypher.Filter then you can use the Session.loadAll methods which accept Filters as well as a depth. MusicIntegrationTest contains a couple of Filter examples.

Luanne
  • 19,145
  • 1
  • 39
  • 51
0

For others reference, I followed Option b as suggested by @Luanne.

here is code snippet

def getByUuid[T](klazz: Class[T], uuid: String): T = {
    IterableUtils.getSingleOrNull(session.loadAll(klazz, new Filter("uuid", uuid), 1))
}
Gaurav Abbi
  • 645
  • 9
  • 23
0

i know its been forever from last answer but someone might have trouble with this issue aswell ..

i guess ogm has covered this exception by updating it.Because prev. relationships are not deleting anymore.(tested with ogm 2.0.5 & neo4j 3.0.7.)

ps. query with 1 depth can reduce your execution time realy bad. so dont use it anymore unless its necessary.