After
I am trying to map the following:
public class person {. .. @ ManyToMany (cascade = {CascadeType.PERSIST, CascadeType.MERGE}) @JoinTable (name = "person_categories", joinColumns = @JoinColumn (name = "personId"), inverseJoinColumns = @JoinColumn (name = "CategoryID")) Set up private & lt; Category & gt; Categories ...} Public Category Category {@Id @GeneratedValue (strategy = GenerationType.AUTO) @column (name = "rangeID") private integer ID; @Column (unique = true) private string name ...}
When I try to save a person object, is inserted categories, but are stored in duplicate table is. How can I ensure that each category is unique in its table and maintaining transitivity? I have tried to make the name column unique, but it only helped by throwing the barrier errors.
If you do not override hashCode () and equals () to be meaningful class, you will get a duplicate in your set (if you are adding a duplicate to start with). If the name field separates objects, try:
public integer hashCode () {return name.hashCode (); } Public object equal (object o) {if (o installation range) {return ((category) o) .name.equals (this.name); } return false; }
Comments
Post a Comment