[英]Hibernate criteria.setFetchMode(property, mode) is not working for child property in an entity
I have a class defined; 我定义了一个类;
@Entity
@Table(name = "atg", uniqueConstraints = @UniqueConstraint(columnNames = "code"))
public class ATG{
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "companyid")
Manufacturer manufacturer;
..
}
When I try to fetch ATG entities with Manufacturer, I set like; 当我尝试通过制造商获取ATG实体时,我会设置为;
criteria.setFetchMode("manufacturer", FetchMode.JOIN);
And that is working. 那是可行的。 Means I get Manufacturer details.
意味着我得到了制造商的详细信息。
I have Manufacturer class defined as; 我将制造商类定义为:
@Entity
public class Manufacturer{
@OneToMany( mappedBy="manufacturer")
private List<Site> sites;
}
I want to fetch site object too. 我也想获取站点对象。 So, I did like,
所以,我确实喜欢
criteria.setFetchMode("manufacturer.sites", FetchMode.JOIN);
But this is not working. 但这是行不通的。 That is, I could not get Site list.
也就是说,我无法获得网站列表。
How should I use FetchMode.Join in this case? 在这种情况下,我应该如何使用FetchMode.Join?
You can try to put createAlias() in your criteria. 您可以尝试将createAlias()放入条件中。 See sample
查看样本
criteria.createAlias("manufacturer.sites","site",CriteriaSPecification.LEFT_JOIN);
criteria.setFetchMode("site", FetchMode.JOIN);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.