1
我正在使用JPA 2.0並希望使用XML創建唯一約束,而不是註釋。JPA 2.0作爲XML的唯一約束條件
被註解類看起來是這樣的:
@Entity
public class Person {
@Id
@GeneratedValue
private Long id;
@Column(unique=true)
private String name;
// ..
}
而且orm.xml
文件這樣的 - 它雖然缺少唯一約束:
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0">
<entity class="kiosk.model.Person">
<attributes>
<id name="id">
<generated-value strategy="AUTO" />
</id>
<basic name="name" />
<!-- .. -->
</attributes>
</entity>
</entity-mappings>
如何唯一約束添加到JPA 2.0類使用XML?