1
進出口使用休眠休眠註釋唯一約束,9.1 Postgres的,我試圖通過休眠註釋(不在數據庫中明確加入)不能創建在Postgres數據庫
然而,DB添加一個唯一約束忽略唯一註釋並且不會創建約束。我也嘗試添加該限制在@Table批註,但沒有太
@Entity
public class Person implements Serializable {
@Id
@Column(insertable=false, updatable=false)
@Type(type="java.lang.Long")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="PERSON_SEQ")
@SequenceGenerator(name="PERSON_SEQ", sequenceName="PERSON_SEQ", allocationSize=1)
private Long id;
@Column(unique=true)
private String username;
}
的hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/Test1</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">postgres</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hbm2ddl.auto">update</property>
</session-factory>
您是如何確定約束被忽略的? – axtavt 2012-01-08 09:25:13
約束不會傳遞給數據庫。 另外,我測試它,它讓我創建重複的用戶名 – geo 2012-01-08 09:29:34