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)
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.
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* – (?)
Sorry to raise the dead here, but I find I still have strange mapping reports, all the while mapping is working perfectly. I get a lot of this, is it normal?
ERROR 3537 --- [ctor-http-nio-4] org.neo4j.ogm.context.GraphEntityMapper : Found more than one matching @RelationshipEntity for (9596)-[PRESENTS]->(9610) but cannot tell which one to use
This relates to my original post because it has to do with the same root issue: either I fundamentally misunderstand how the mapper works, or the mapper has a fundamental weakness in regards to directionality.