Closed biliboc closed 6 years ago
@biliboc it looks like you're returning a path which contains both nodes- CMITOCAR and CMITOCAR2 with the same labels, so the OGM is unable to tell which node you're expecting. It is better to return the node you want, along with relationships and other nodes in the path (because I'm assuming you want a hydrated entity). http://graphaware.com/neo4j/2016/04/06/mapping-query-entities-sdn.html may be helpful.
I really don't get it why you cannot do that: In the domain object the type of the relationship is stated: one is OWNER and the other one is SHARED_WITH. In the structure returned by the server those relationships are also returned including their differentiating type. So the distinction should not have stopped here just at the label of the sub object but use the type of the relationship. You have all the info necessary. At this level, OGM is introducing a unnecessary constraint as all the info needed is returned by the server.
What does Thing.java look like? And which version of the OGM are you using?
<neo4j.ogm.version>2.0.1</neo4j.ogm.version>
@NodeEntity(label="Thing")
public class Thing extends AbstractNamedOwnedObject implements Attributable {
protected String type;
protected String uuid;
@Relationship(type= "HAS_ATTR", direction = Relationship.OUTGOING)
protected Set<NodeAttr> attrs;
@Relationship(type= "SHARED_WITH", direction = Relationship.OUTGOING)
private Set<Thing> sharedWith;
....
}
So Thing
does not have references back to DataView
for the OWNER
and SHARED_WITH
relationships?
It does not. By the way I do not use the repositories provided by SDN but using session.query() I built my own Repository interface as I did not like the constrains SDN is enforcing
Do you see the same mapping problem when you load the DataView by id? Using the session/template load/find one?
The same problem when loading dataview by ID:
@Override
public T find( Long id, int depth ) {
return session.load( getEntityType(), id, depth );
}
Confirmed as a bug. As a temporary workaround, until we can provide a fix, we believe that if you are able to change the DataView's owner to List<Thing> owners
rather than a singleton Thing owner
, it will work as you expect. The owner will not appear in the List<Thing> shared
collection.
Alternatively, if you add the corresponding incoming relationship to the singleton owner on the Thing
it should also solve the problem:
@Relationship(type="OWNER", direction = "INCOMING")
DataView dataView;
Ok I will do an workaround. You guys need to stop enforcing sub objects to have a link to parent objects. In my case the sub object represents a user which is a owner of thousands of objects. If, by mistake, I would have saved that object I would lose all the links to the objects that owns.
Deferred till entity mapping strategies are discussed. Another workaround is to annotate the setters as well in DataView.java
This now seems to be working as expected?
@luanne can you confirm?
I think this now works as it should, if not please reopen with a test case provided.
I have this domain object
`@NodeEntity(label="DataView") public class DataView extends AbstractNamedOwnedObject {
}`
and this query
START s=node(4028) MATCH (s:DataView)-[:OWNER|SHARED_WITH]->(u:_GraphUser_ {name:"cmitocar"}) WITH s MATCH p=()<-[:OWNER|SHARED_WITH*0..1]-(s)-[:VIEW_ATTR|VIEW_PART|VIEW_REL|DW_R_END|W_R_START|W_R_END|HAS_ATTR|W_HAS_ATTR*0..3]-(m) RETURN p
return session.queryForObject(DataView.class, "START s=node({sid}) MATCH (s:DataView)-[:OWNER|SHARED_WITH]->(u:_GraphUser_ {name:{username}}) WITH s MATCH p=()<-[:OWNER|SHARED_WITH*0..1]-(s)-[:VIEW_ATTR|VIEW_PART|VIEW_REL|DW_R_END|W_R_START|W_R_END|HAS_ATTR|W_HAS_ATTR*0..3]-(m) RETURN p", ImmutableMap.<String,Object>of( "sid", id, "username", username ) );
returns the right object BUT in the
sharedWith
field there is one entry that is the same value in theowner
As per image attached it should return @
'cmitocar2'
node.SIMPLIFICATION:
REQUEST
{"statements":[{"statement":"START s=node({sid}) MATCH (s:DataView)-[:OWNER|SHARED_WITH]->(u:_GraphUser_ {name:{username}}) WITH s MATCH p=()<-[:OWNER|SHARED_WITH]-(s) RETURN p","parameters":{"sid":4028,"username":"cmitocar"},"resultDataContents":["graph"],"includeStats":false}]}
OUTPUT ``