I found this before:
There's a code snippet on the first answer:
@Entity
public class UserRole {
@Id
@GeneratedValue
private long id;
@NaturalId
private User user;
@NaturalId
private Role role;
}
So, not using artificial dummy IDs, how would the class look like?
@Entity
public class UserRole {
@?
@NaturalId
private User user;
@?
@NaturalId
private Role role;
}
Do I need an inner "ID class" nontheless? Can I use @IdClass on the two references instead (where marked "@?")?
I'd really find it more natural to override equals and hashCode in this class instead of the "ID class", so such a design would be a lot better. Can you produce something like the above and if so, which annotations do you need?
Karsten