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?