Hibernate version: 3.2-cr2
Annotations: 3.2.0-CR1
Here is my model: a User doesn't contain directly his roles but it has a component AccessInfo with these roles. But the Role refers to User...
Code:
@Entity
public class User {
private AccessInfo accessInfo;
[...]
}
@Embeddable
public class AccessInfo {
@ManyToMany
@JoinTable(name = "user_role", joinColumns = { @JoinColumn(name = "userId") }, inverseJoinColumns = { @JoinColumn(name = "roleId") })
private Set<Role> roles;
[...]
}
@Entity
public class Role {
@ManyToMany(targetEntity = User.class, mappedBy = "accessInfo.roles")
@JoinTable(name = "user_role", joinColumns = { @JoinColumn(name = "roleId") }, inverseJoinColumns = { @JoinColumn(name = "userId") })
private Set<User> users;
[...]
}
My parameter "mappedBy" in the @ManyToMany association in Role is wrong but I don't know how to define it.
I read in the documentation:
Quote:
You cannot use association annotations in an embeddable object (ie no @*ToOne nor @*ToMany). This is disallowed
by the spec, and not yet supported in Hibernate Annotations.
But does this apply to this pattern or to an association of components ?
Do I have an other choice than merge my User and my AccessInfo into a single bean ?
Thanks in advance
Cedric