I have defined a many-to-many relationship between my two entity classes User and Permission. User has a primary key composite of username and countyId, and my Permission ta
In order to solve referencedColumnName exception
In User put
@ManyToMany(cascade={CascadeType.PERSIST, cascadeType.MERGE})
private Collection<Permission> permissions;
And in Permission
@ManyToMany(mappedBy="permissions")
@JoinTable(name="tblUserPermission",
joinColumns={@JoinColumn(name="permissionId", referencedColumnName="permissionId")},
inverseJoinColumns={
@JoinColumn(name="username", referencedColumnName="username"),
@JoinColumn(name="countyId", referencedColumnName="countyId")})
private Collection<User> users;
UserId class
public class UserId implements Serializable {
private String username;
private Integer countyId;
// getter's and setter's
public boolean equals(Object o) {
if(o == null)
return false;
if(!(o instanceof UserId))
return false;
UserId id = (UserId) o;
if(!(getUsername().equals(id.getUsername()))
return false;
if(!(getCountyId().equals(id.getCountyId()))
return false;
return true;
}
public int hachcode() {
// hashcode
}
}
Then in User class put
@Entity
@Table(name="tblUser")
@IdClass(UserId.class)
public class User ... {
@Id
private String username;
@Id
private Integer countyId;
}
regards,