1
イムで休止状態アノテーションでユニーク制約の作成に失敗し、私は(データベースに明示的に追加していない)休止アノテーションを介して、ユニーク制約を追加しようとしています一意の注釈を無視し、制約を作成しません。私も@Table注釈にcontraintを追加しようとしましたが、あまりにも失敗したはPostgresの9.1、休止状態使用してPostgresデータベース
@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
制約はdbに渡されません。 また、テストして、重複したユーザー名を作成できるようにしました – geo