3 Replies Latest reply on Jul 18, 2008 5:02 PM by Matt Davis

    Annotation @Column(unique=true) does not prevent duplicate insertions

    Phil Haigh Novice

      I have a simple model class:



      @Entity
      @Table(name = "destinations")
      public class Destination implements Serializable
      {
              private static final long serialVersionUID = 1L;
      
              @Id
              @GeneratedValue
              private Long id;
              @Length (max=75)
              private String title;
              @Length (max=500)
              private String description;
              @Length (max=1000)
              private String keywords;
              
              @Length (max=100)
              @Column (name="name",unique=true)       
              private String name;
      //snip



      I expected this would prevent persistance of destinations with duplicate names.. however, the application still allows me to add as many destinations with the same name as I like.


      How can I use the @Column(unique=true) annotation to enforce this?