0

I am using Hibernate with EJB 3 (no xml). I need to implement a logic for prevent duplicate data. I have got class like this:

public class CvnCity  implements java.io.Serializable {

   private Integer idCity;
   private String city;

   public CvnCity() {
   }  

   public CvnCity(String city) {
      this.city = city;
   }

   @Id @GeneratedValue(strategy=IDENTITY)

   @Column(name="ID_CITY", unique=true, nullable=false)
   public Integer getIdCity() {
      return this.idCity;
   }
...

}

Another like this:

public class Person implements java.io.Serializable {

   private Integer idPerson;
   private String name;
   private City city;

   ...

}

I want to prevent insert Person with the same name and with the same city, also, i need to expand this issue to many class so i though to implement a general logic that only has as input, the "uniques" fields.

4

1 回答 1

0

查看NaturalIdHibernate Annotations Reference Section 2.2.3.2. Composite identifier

于 2012-04-23T17:28:57.267 回答