我无法提出与以下内容等效的(合法)外部映射:
@Entity
public class EntityX {
@Id
private Long id;
@ElementCollection
@Column(name = "month")
@Convert(converter = YearMonthConverter.class)
private Set<YearMonth> months;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public Set<YearMonth> getMonths() { return months; }
public void setMonths(Set<YearMonth> months) { this.months = months; }
}
我能得到的最接近的是:
<entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm http://xmlns.jcp.org/xml/ns/persistence/orm_2_2.xsd" version="2.2">
<entity class="EntityX">
<attributes>
<id name="id" />
<element-collection name="months">
<column name="month" />
<convert converter="YearMonthConverter"/>
</element-collection>
</attributes>
</entity>
</entity-mappings>
唯一的问题是,根据XSD,此XML是非法的。
幸运的是,您可以克隆https://github.com/perceptron8/entity-mappings并运行测试以查看Hibernate 5.x不符合要求。
是否存在另一种合法的XML格式表示方式? 还是这是JPA 2.2 spec中的错误?