I have four tables:
Roles the roles in the system
ACCESS_TYPE: read, write, etc
Property: resources in the system
I have a ternary associations represented by a fourth table:ROLE_MAPPING
I created three entities to represent the roel, property and access type. I wanted
to represent the ternary relation by using a map inside the entity Role. I am struggling with
that. Can someone please help me.
Code:
TABLE ROLE(ID INT,
ROLETYPE VARCHAR(20),
);
TABLE ACCESS_TYPE(ID INT,
NAME VARCHAR(10));
TABLE Property(ID INT
NAME VARCHAR(30));
TABLE ROLE_MAPPING(ROLE_ID INT,
Property_ID INT,
PRIMARY KEY(ROLE_ID, Property_ID),
ACCESS_TYPE_ID INT NOT NULL
);
@Table(name = "role")
public class Role implements DataObject, Serializable {
@ManyToMany(targetEntity=Property.class)
@MapKey(name="Property_ID")
@JoinTable(
table=@Table(name="ROLE_MAPPING"),
joinColumns={@JoinColumn(name="ROLE_ID")},
inverseJoinColumns={@JoinColumn(name="Property_ID")})
}
thanks