javax.persistence.Column 的unique 是设置一个字段唯一现在我要设置两个字段。。比如姓、名。。姓可以一样 名可以一样 但是姓名一起不能一样 该怎么设置Hibernatepersistence注释建表

解决方案 »

  1.   

    @Table(uniqueConstraints=@UniqueConstraint(columnNames = {"姓", "名"})) 
      

  2.   

    @Entity
    @Table(uniqueConstraints=@UniqueConstraint(columnNames={"preferenceType","nightClub_id"}))
    public class Preference {
    /**
     * id
     */
    @Expose
    @Id
    @GeneratedValue
    private Integer id;
    /**
     * 用户
     */
    @Expose
    @ManyToOne
    private User user;
    /**
     * 偏好类型
     */
    @Expose
    @Enumerated(EnumType.STRING)
    private PreferenceType preferenceType;
    /**
     * 夜店
     */
    @Expose
    @ManyToOne
    private NightClub nightClub;
    /**
     * 活动类型
     */
    @Expose
    @ManyToOne
    private EventType eventType;而且我发现 还要加个用户。。- - 所以是要约束3个字段 怎么破
      

  3.   

    求大神解决问题。。目测是因为ManyToOne 的原因么
      

  4.   

    这个有帮助么 http://amchencute.iteye.com/blog/418138