如何将集合设置@LazyCollection(LazyCollectionOption.FALSE)
在 hyperjaxb 中?
这是示例: 我有一个 xml 节点ab
,它可以包含 type 的子节点cd
列表或 type 的子节点列表ef
。两者cd
且ef
仅包含文本/字符串内容。我有一个 xsd 定义,我通过 JAXB 和 hyperjaxb 运行它来创建带有休眠注释的 java 类,并带有数据库表。我如何让 hyperjaxb@LazyCollection(LazyCollectionOption.FALSE)
为每个集合设置,而不是设置 fetchtype?
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;
}
}