Reputation: 14719
I'm starting with OrientDB and I got the basics right. But I can't figured out how to map many-to-many relationships in a way that won't require me to make tons of integrity checking when removing a record.
I am using an object database (ODatabaseObjectTx) and I'm trying to map this simple relationship:
Person <-> Roles
A Person can have multiple Roles and a Role can be assigned to multiple Persons. N to M relationship.
My person class:
public class Person {
private String name;
public Person() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
My Role class:
public class Role {
private String name;
public Role() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Now I can't figure out if I have to put a Set<Role>
in the User
class or a Set<User>
in the Role
class to make the links. Either way if I remove one record from one I have to check the links of the other to avoid null
references. To me it is more convenient to place a Set<Role>
in the User
class.
In a RMDBS you can just create a foreign key and add some cascading rules, does OrientDB provide similar functionality to save me the bother of doing this manually?
If in the end I have to do this manually, what strategy should I take? Should I fully check the other cluster when removing a record? Should I just leave the null
s and handle them when I see them? Should I create double references (having both Set<Role>
in User
AND Set<User>
in Role
, I guess this would bring faster removal at the cost of more space and complexity)?
Upvotes: 4
Views: 855
Reputation: 1023
take a look at documentation: https://github.com/orientechnologies/orientdb/wiki/Object-Database#cascade-deleting
Upvotes: 0