如何在hyperjaxb中将集合设置为@LazyCollection(LazyCollectionOption.FALSE)?
这里是一个示例: xml有一个节点ab,它可以包含cd类型的子节点列表,也可以包含ef类型的子节点列表。cd和ef都只包含文本/字符串内容。我有一个xsd定义,我通过JAXB和hyperjaxb运行该定义来创建带有hibernate注释的java类,并使用数据库表完成。不是设置获取类型,而是如何让hyperjaxb为每个集合设置@LazyCollection(LazyCollectionOption.FALSE)?
xml看起来像:
<ab>
<cd>Some thing</cd>
<cd>Another thing</cd>
</ab>或者:
<ab>
<ef>Some thing</ef>
<ef>Another thing</ef>
</ab>xsd如下所示:
<xs:complexType name="Ab">
<xs:sequence>
<xs:element name="cd" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="ef" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>生成的实体应该如下所示:
@Entity(name = "Ab")
@Table(name = "AB")
@Inheritance(strategy = InheritanceType.JOINED)
public class Ab implements Equals, HashCode {
protected List<String> cd;
protected List<String> ef;
@XmlAttribute(name = "Hjid")
protected Long hjid;
protected transient List<Ab.AbCdItem> cdItems;
protected transient List<Ab.AbEfItem> efItems;
@OneToMany(targetEntity = Ab.AbCdItem.class, cascade = {CascadeType.ALL})
@JoinColumn(name = "CD_ITEMS_AB_HJID")
@LazyCollection(LazyCollectionOption.FALSE)
public List<Ab.AbCdItem> getCdItems() {
if (this.cdItems == null) {
this.cdItems = new ArrayList<Ab.AbCdItem>();
}
if (ItemUtils.shouldBeWrapped(this.cd)) {
this.cd = ItemUtils.wrap(this.cd, this.cdItems, Ab.AbCdItem.class);
}
return this.cdItems;
}
@OneToMany(targetEntity = Ab.AbEfItem.class, cascade = {CascadeType.ALL})
@JoinColumn(name = "EF_ITEMS_AB_HJID")
@LazyCollection(LazyCollectionOption.FALSE)
public List<Ab.AbEfItem> getEfItems() {
if (this.efItems == null) {
this.efItems = new ArrayList<Ab.AbEfItem>();
}
if (ItemUtils.shouldBeWrapped(this.ef)) {
this.ef = ItemUtils.wrap(this.ef, this.efItems, Ab.AbEfItem.class);
}
return this.efItems;
}
}发布于 2014-11-19 08:46:05
@LazyCollection,或@org.hibernate.annotations.LazyCollection (以完全限定的形式)是一种专有Hibernate注释,而不是JPA标准。
Hyperjaxb只支持标准的JPA1.0和2.0注释,因此不支持@LazyCollection。
奥顿:
https://stackoverflow.com/questions/26984496
复制相似问题