En utilisant Hibernate 3.6.7 et JPA 2, je ne peux pas avoir deux jointures de fetch dans une requête. L'entité a un champ d'auto-référence appelé parent. localizedTexts est un @ElementCollection
, de type Java de Map. entity.getParent() a une stratégie de chargement @ManyToOne avec EAGER.Plusieurs jointures de fetch JQPL échouent avec Hibernate
Voici comment l'entité ressemble:
@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;
}
/* ... */
}
Les deux requêtes suivantes fonctionnent:
select e from Entity e join fetch e.parent.localizedTexts
select e from Entity e join fetch e.localizedTexts
Mais cela ne fonctionne pas:
select e from Entity e join fetch e.localizedTexts join fetch e.parent.localizedTexts
Hibernate se plaint: 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]
Aucune différence. La même exception est levée pour cette requête: select e de l'entité e join e.parent p jointure fetch e.localizedTexts jointure fetch p.localizedTexts – Mohsen
Si vous avez une association OneToMany ou oneTOOne de e à parent et une onetoMany de parent à localizedTexts ci-dessus rejoindre devrait fonctionner. S'il vous plaît poster un code coupé de ces beans et leurs associations entre eux –
comme mentionné précédemment localizedTexts est MapKeyColumn, et il y a un ManyToOne sur getParent() – Mohsen