OGM RelationshipEntity between nodes of same label


(Jiropole) #1

Weird question, but I can't find any related docs. In most cases, whenever I'm mapping through @Relationship entities, the source and target nodes have differing labels / model classes. Now I have a case where I need to map sources and targets of the same label / model class. This appears to trip up the OGM, and it doesn't know which of the returned nodes should be the source and which the target, even though the relationship is clearly indicated (and returned by the query).

Does this sound like an unsupported mapping, or more like I'm doing it wrong? Code example:

@NodeEntity
data class Thing(@Id @GeneratedValue(strategy = UuidStrategy::class) var uuid: String? = null,
                                   @Relationship(type = "AUGMENTS", direction = Relationship.OUTGOING
                                   var augments: List<ThingAugments>? = null) { ... }

@RelationshipEntity(type = "AUGMENTS")
data class ThingAugments(@Id @GeneratedValue var id: Long? = null,
                                   @Property(name = "order") var order: Long? = null,
                                   @StartNode var source: Thing? = null,
                                   @EndNode var target: Thing? = null)

(Jiropole) #2

Nevermind – this was an issue with my (overly complicated) cypher query.


(Jiropole) #3

Oops. Fixing the cypher corrected the mapping problem. And while it now maps the (t1:Thing)-[:AUGMENTS]->(t2:Thing) properly, it also spills all the t2's to the top level, returning an array of Things. This will break e.g. calls that return a single object versus a list, and generally adds noise.

But it makes sense – I guess OGM must return all objects matching return type. I have no idea how to address this one, though. And sorry – this is specifically via SDN, using custom @Query on Repository calls.


(Gerrit Meier) #5

I assume that it is related to this GitHub issue https://github.com/neo4j/neo4j-ogm/issues/496 that was solved with this commit: https://github.com/neo4j/neo4j-ogm/commit/3532cc0f02b5e768dee15720b2e858991fc9124a
You may test it by using the latest Spring Data Neo4j Moore Milestone (M1) and set the Neo4j-OGM version to 3.2.0-alpha04.


(Jiropole) #6

Perhaps, but for me it happens whether or not I'm using a pattern comprehension. But, if I do send the same @Query as would have been sent (or at least, logged) from e.g. FindBy* (which uses comprehensions), it exhibits the issue. Yet works for FindBy* – (?)


(Jiropole) #7

@gerrit.meier Thank you for the advice. Unfortunately, I am unable to get this combination of releases working in my project:

Failed to instantiate [org.neo4j.ogm.session.SessionFactory]: Factory method 'sessionFactory' threw exception; nested exception is java.lang.NoSuchMethodError: org.neo4j.ogm.config.Configuration.mergeBasePackagesWith([Ljava/lang/String;)[Ljava/lang/String;