Hibernate没有生成唯一约束

时间:2013-08-14 08:42:47

标签: mysql hibernate jpa jboss

我有以下实体,我希望列名称是唯一的。出于某种原因,Hibernate在自动生成表时不会生成任何唯一约束。关于为什么Hibernate没有强制执行这个独特约束的任何想法?我在JBoss EAP 6.1上运行MySQL 5.5和Hibernate 4.2.0。

@Entity
@Table(name = "Address", uniqueConstraints = @UniqueConstraint(columnNames = { "Name" }))
public class AddressEntity {

    private int id;
    private String name;
    private String streetAddress;
    private String country;
    private String city;
    private String zip;

    @Id
    @GeneratedValue
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Column(name = "Name", unique = true, nullable = false)
    public String getName() {
        return name;
    }

    // getters and setters...
}

1 个答案:

答案 0 :(得分:1)

尝试从uniqueConstraint删除@Table