问题描述
在Hibernate中,为什么我应该使用JPA标记: @Table(name =tbl_sky,
uniqueConstraints = {@UniqueConstraint(columnNames = {month,day})}
)
我知道何时使用它。它在数据库表的字段(元组)是唯一的时候使用。当存在复合主键时它不会被使用,因为复合主键始终是唯一的。无论如何,数据库已经实施了这种唯一约束关系,那么在我的Hibernate注释中包含这个标签有什么意义呢?如何使用这个标签帮助Hibernate?
它有助于映射的模式生成(DDL)中的休眠。查看:
In Hibernate, why should I use the JPA tag:
@Table(name="tbl_sky",
uniqueConstraints = {@UniqueConstraint(columnNames={"month", "day"})}
)
I know when to use it. It's used when the combination of fields (tuple) of a database table is unique. It's not used when there is a composite primary key because composite primary keys are always unique. Anyway, the database already enforces this "unique constraint" relationship, so what's the point of including this tag on my Hibernate annotations? How does using this tag help Hibernate?
It helps hibernate in schema generation (DDL) for your mappings. Look at: http://docs.oracle.com/javaee/6/api/javax/persistence/UniqueConstraint.html
这篇关于JPA @UniqueConstraint在Hibernate中做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!