Reputation: 83
I am using a AGE and its JDBC driver, and I want to implement Object-Graph Mapping (OGM) in my application. I have a graph database of employees where nodes represent Person, City, and Department.
In my Java application, I want to map these nodes to Java classes so that I can work with the data in an object-oriented way. For example, the Person node should map to a Person Java class, the City node should map to a City Java class, and the Department node should map to a Department Java class.
In addition, I want to store the relationships between nodes as Java object references. For example, if there is a relationship between a Person node and a City node, this relationship should be represented as a reference from the Person Java object to the City Java object.
I am looking for help on how to implement OGM in my graph database and Java application. Can someone provide me with an example or some guidance on how to achieve this mapping?
Upvotes: 2
Views: 217
Reputation: 48
You can use neo4j library for object graph mapping in Java. The process is overall simple just like object relational modelling where we map each entity to a class.
In your case, you would have classes like Person and Department.
@NodeEntity
public class Department {
@id
String name;
@Relationship(type = "WORKED", direction = Relationship.Direction.INCOMING)
List<Person> employees;
}
@NodeEntity
public class Person {
@id
String name;
}
Check out the documentation of neo4j to properly configure it in your development environment.
Upvotes: 1