-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Recursive structures with Neo4j
PostPosted: Tue May 09, 2017 4:33 pm 
Beginner
Beginner

Joined: Thu Jan 05, 2017 1:47 pm
Posts: 27
We have a reflexive relationship which doesn't seem to come out of the database properly:

Code:
  class AbstractEquipment {
    ...
    @ManyToOne(optional = true, fetch = FetchType.EAGER)
    @JoinTable(name = "EQUIPMENT_ABSTRACTEQUIPMENT_PARENT")
    private com.nokia.nspos.model.domain.equipment.entities.AbstractEquipment parent;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true)
    private java.util.List<com.nokia.nspos.model.domain.equipment.entities.AbstractEquipment> children;
    ...
  }

The parent field seems to get populated correctly, but the children collection always contains the parent in addition to the children that were persisted.

I have all the Cypher queries, but I think this one is the one that is intended to fetch the children:

Code:
neo4j-sh (?)$ MATCH (owner:ENTITY:`EQUIPMENT_ABSTRACTEQUIPMENT` {dbId: 54}) -[r:parent]- (target) RETURN id(target), r, owner, target ORDER BY id(target);
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id(target) | r              | owner                                                                                                                                                                                                                                                                                                                                                     | target                                                                                                                                                                                                                                                                                                                                                                                                                  |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 68         | :parent[92]{}  | Node[96]{_modelVersion:"1.0.0",_fullClassName:"equipment.Equipment",operState:0,neName:"7750_sim_234",oosReason:0,adminState:1,DTYPE:"equipment_Equipment",sourceType:2,position:"shelf=1/slot=2/card=2/slot=1/card=1",name:"Daughter Card - 2/1",_version:0,type:3,positionId:2,neId:"35.121.0.234",standbyState:1,sourceSystem:"fdn:realm:sam",dbId:54} | Node[68]{_modelVersion:"1.0.0",_fullClassName:"equipment.EquipmentHolder",operState:0,_version:0,sourceType:2,oosReason:0,adminState:1,neId:"35.121.0.234",neName:"7750_sim_234",DTYPE:"equipment_EquipmentHolder",actualType:"1",position:"shelf=1/slot=2/card=2/slot=1",name:"Daughter Card Slot - 2/1",type:3,positionId:2,holderState:1,provisionedType:"4096",standbyState:1,sourceSystem:"fdn:realm:sam",dbId:47} |
| 196        | :parent[192]{} | Node[96]{_modelVersion:"1.0.0",_fullClassName:"equipment.Equipment",operState:0,neName:"7750_sim_234",oosReason:0,adminState:1,DTYPE:"equipment_Equipment",sourceType:2,position:"shelf=1/slot=2/card=2/slot=1/card=1",name:"Daughter Card - 2/1",_version:0,type:3,positionId:2,neId:"35.121.0.234",standbyState:1,sourceSystem:"fdn:realm:sam",dbId:54} | Node[196]{oosReason:0,adminState:1,operState:2,_modelVersion:"1.0.0",sourceType:2,_fullClassName:"equipment.Equipment",neId:"35.121.0.234",neName:"7750_sim_234",description:"10-Gig Ethernet",_version:0,position:"shelf=1/slot=2/card=2/slot=1/card=1/port=1",DTYPE:"equipment_Equipment",type:9,positionId:1,name:"Port 2/1/1",standbyState:1,sourceSystem:"fdn:realm:sam",dbId:79}                                  |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows
59 ms


I think there needs to be a direction constraint on the edge [r:parent] like this:

Code:
neo4j-sh (?)$ MATCH (owner:ENTITY:`EQUIPMENT_ABSTRACTEQUIPMENT` {dbId: 54}) <-[r:parent]- (target) RETURN id(target), r, owner, target ORDER BY id(target);
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id(target) | r              | owner                                                                                                                                                                                                                                                                                                                                                     | target                                                                                                                                                                                                                                                                                                                                                                                 |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 196        | :parent[192]{} | Node[96]{_modelVersion:"1.0.0",_fullClassName:"equipment.Equipment",operState:0,neName:"7750_sim_234",oosReason:0,adminState:1,DTYPE:"equipment_Equipment",sourceType:2,position:"shelf=1/slot=2/card=2/slot=1/card=1",name:"Daughter Card - 2/1",_version:0,type:3,positionId:2,neId:"35.121.0.234",standbyState:1,sourceSystem:"fdn:realm:sam",dbId:54} | Node[196]{oosReason:0,adminState:1,operState:2,_modelVersion:"1.0.0",sourceType:2,_fullClassName:"equipment.Equipment",neId:"35.121.0.234",neName:"7750_sim_234",description:"10-Gig Ethernet",_version:0,position:"shelf=1/slot=2/card=2/slot=1/card=1/port=1",DTYPE:"equipment_Equipment",type:9,positionId:1,name:"Port 2/1/1",standbyState:1,sourceSystem:"fdn:realm:sam",dbId:79} |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row
32 ms


If that's not the one let me know. I can submit the other queries and results too.


Top
 Profile  
 
 Post subject: Re: Recursive structures with Neo4j
PostPosted: Thu May 11, 2017 8:28 am 
Beginner
Beginner

Joined: Thu Jan 05, 2017 1:47 pm
Posts: 27
I've tried reversing the mappedBy so that the 'children' owns the association, but after about 10 objects are added to the db the following query starts taking ~30s to run:

Code:
MATCH (owner:ENTITY:`EQUIPMENT_ABSTRACTEQUIPMENT` {dbId: {0}}) OPTIONAL MATCH (owner) -[r*]->(emb:EMBEDDED) RETURN owner, r, emb


Top
 Profile  
 
 Post subject: Re: Recursive structures with Neo4j
PostPosted: Thu May 11, 2017 8:44 am 
Beginner
Beginner

Joined: Thu Jan 05, 2017 1:47 pm
Posts: 27
Oops, actually it turns out what I was just testing was two unidirectional relationships. Setting mappedBy=children isn't possible of course.


Top
 Profile  
 
 Post subject: Re: Recursive structures with Neo4j
PostPosted: Fri May 12, 2017 11:05 am 
Beginner
Beginner

Joined: Thu Jan 05, 2017 1:47 pm
Posts: 27
I have a potential fix for this. How might I go about contributing?


Top
 Profile  
 
 Post subject: Re: Recursive structures with Neo4j
PostPosted: Mon May 29, 2017 4:25 pm 
Beginner
Beginner

Joined: Thu Jan 05, 2017 1:47 pm
Posts: 27
Bump?


Top
 Profile  
 
 Post subject: Re: Recursive structures with Neo4j
PostPosted: Wed May 31, 2017 8:08 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
You can contribute by forking our master project on github, apply the change and send a PR.

You can find some information on this page: http://hibernate.org/ogm/contribute/

You can find our template for the code here: https://github.com/hibernate/hibernate-ide-codestyles

Thanks,
Davide


Top
 Profile  
 
 Post subject: Re: Recursive structures with Neo4j
PostPosted: Wed May 31, 2017 9:08 am 
Beginner
Beginner

Joined: Thu Jan 05, 2017 1:47 pm
Posts: 27
I created pull request https://github.com/hibernate/hibernate-ogm/pull/861


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.