@UniqueConstraint annotation in Java

后端 未结 8 1560
囚心锁ツ
囚心锁ツ 2020-12-02 05:20

I have a Java bean. Now, I want to be sure that the field should be unique.

I am using the following code:

@UniqueConstraint(columnNames={\"username\         


        
8条回答
  •  眼角桃花
    2020-12-02 05:49

    I'm currently using play framework too with hibernate and JPA 2.0 annotation and this model works without problems

    @Entity
    @Table(uniqueConstraints={@UniqueConstraint(columnNames = {"id_1" , "id_2"})})
    public class class_name {
    
    @Id
    @GeneratedValue
    public Long id;
    
    @NotNull
    public Long id_1;
    
    @NotNull
    public Long id_2;
    
    }
    

    Hope it helped.

提交回复
热议问题