Unique items in Hibernate collections
        Posted  
        
            by Rickard Lindberg
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Rickard Lindberg
        
        
        
        Published on 2010-06-18T07:23:44Z
        Indexed on 
            2010/06/18
            7:33 UTC
        
        
        Read the original article
        Hit count: 548
        
I have defined a collection in Hibernate like this:
...
public class Item {
    ...
    @ElementCollection
    List<Object> relatedObjects;
}
It creates a mapping table with colums item_id and object_id.
The problem is that object_id seems to be unique. In other words I can not have two different items being related to the same object. But that is what I want.
I would like the combination of item_id and object_id to be unique. How do I do that?
© Stack Overflow or respective owner