I have four table like USER, ROLE, PERMISSION and USERROLEPERMISSION.
I have a composite Primary Key in USERROLEPERMISSION and all the fields in the composite primary key are also foreign keys.
The primary keys for these table are
1. USER : UserID
2. ROLE : RoleID
3. PERMISSION : PermissionID
4. USERROLEPERMISSION : (UserID,RoleID,PermissionID) and these fields are also foreign key to this table towards the other tables.
I have declared the primary key and foreign key as follows.
Code:
public class UserRolePermissionDetailsDO {
@Id
@JoinColumn(name = "UserID")
@ManyToOne(optional = true)
@ForeignKey(name = "UserID")
private UserDO userDO;
@Id
@JoinColumn(name = "RoleID")
@ManyToOne(optional = true)
@ForeignKey(name = "RoleID")
private RoleDO roleDO;
@Id
@JoinColumn(name = "PermissionsID")
@ManyToOne(optional = true)
@ForeignKey(name = "PermissionsID")
private PermissionDO permissionDO;
In USERDO I have the corresponding entry as below
Code:
@OneToMany(cascade = {CascadeType.REMOVE}, mappedBy="userDO", fetch = FetchType.LAZY)
private Set<UserRolePermissionDetailsDO> userRolePermissionDetailsDO;
In ROLEDO I have the corresponding entry as below
Code:
@OneToMany(cascade = {CascadeType.REMOVE}, mappedBy="roleDO", fetch = FetchType.LAZY)
private Set<UserRolePermissionDetailsDO> userRolePermissionDetailsDO;
In PERMISSIONDO I have the corresponding entry as below
Code:
@OneToMany(cascade = {CascadeType.REMOVE}, mappedBy="permissionDO", fetch = FetchType.LAZY)
private Set<UserRolePermissionDetailsDO> userRolePermissionDetailsDO;
This throws an error
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.org.do.UserRolePermissionDetailsDO.roleDO in com.org.do.RoleDO.userRolePermissionDetailsDO
Any idea please.