How to save entity with relationships and relationship has some relationship properites


(Balatriveni Seelamsetty) #1

How to persist relationship between 2 entities with relationship properties..

In java using OGM


(Usuallycwdillon) #2

Balatriven, Look at the OGM manual here (2.4.3) https://neo4j.com/docs/ogm-manual/current/tutorial/#tutorial:annotations:relationship-entities

Your relationship is really a new java Object that defines the @StartNode and @EndNode, along with any other attributes/properties you want to add. The StartNode and EndNode refers to the node labels (java Classes) that use that relationship.

In your java Class that represents the StartNode, add an @Relationship for the set (or attribute ) of RelationshipEntity object(s). OGM draws the graph the way you would expect. Your java code will have to include the necessary code to get() and set() the objects at StartNode and EndNode.

...at least, that's the way I've made it work.