【发布时间】:2011-11-24 14:23:27
【问题描述】:
使用 Hibernate 3.6.7 和 JPA 2,我不能在一个查询中有两个 fetch 连接。实体有一个称为父的自引用字段。本地化文本是一个@ElementCollection,属于 Java 类型的 Map。 entity.getParent() 有一个带有 EAGER 加载策略的 @ManyToOne。
这是实体的样子:
@Entity
public class Entity extends BaseEntity {
/* ... */
@ManyToOne(fetch = FetchType.EAGER)
public Entity getParent() {
return parent;
}
@ElementCollection
@MapKeyColumn(name = "language")
@Column(name = "text")
public Map<String, String> getLocalizedTexts() {
return localizedTexts;
}
/* ... */
}
以下两个查询有效:
select e from Entity e join fetch e.parent.localizedTexts
select e from Entity e join fetch e.localizedTexts
但这不起作用:
select e from Entity e join fetch e.localizedTexts join fetch e.parent.localizedTexts
休眠抱怨:
query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,collection join,fetch join,fetch non-lazy properties,classAlias=null,role=net.company.project.Entity.localizedTexts,tableName={none},tableAlias=localizedt3_,origin=null,columns={,className=null}}] [select e from net.company.project.Entity e join fetch e.localizedTexts join fetch e.parent.localizedTexts]
【问题讨论】:
标签: java hibernate join fetch jpql