eclipselink.join-fetch not work at all [message #689679] |
Tue, 28 June 2011 03:12  |
Eclipse User |
|
|
|
Hi all,
I have two class ManagedElement and EquipmentHolder,their relationship is as follows:
@Entity
@Table(name="managedelement")
public class ManagedElement
{
@OneToMany(mappedBy="managedElement", fetch=FetchType.LAZY,cascade={CascadeType.ALL})
private Set<EquipmentHolder> equipmentHolders = new HashSet<EquipmentHolder>();
......
}
@Entity
@Table(name="equipmentholder")
public class EquipmentHolder
{
@ManyToOne(cascade={CascadeType.REFRESH,CascadeType.MERGE})
@JoinColumn(name="ME_ID", referencedColumnName="TOPORES_ID")
private ManagedElement managedElement;
......
}
(1)If I set the fetchType of ManagedElment and Equipmentholder to FetchType.EAGER,
I do the follow query:
Query query = em.createQuery("select distinct me from ManagedElement me where me.id="+id);
query.getSingleResult();
With Eclipse IDE debug mode ,I can get the "equipmentHolders" of ManagedElement ,marked in red in the follow Figure.

(2)If I set the fetchType of ManagedElment and Equipmentholder to FetchType.LAZY,
I use the following three queries:
(a)
Query query = em.createQuery("select distinct me from ManagedElement me LEFT JOIN FETCH me.equipmentHolders where me.id="+id);
(b)
Query query = em.createQuery("select distinct me from ManagedElement me where me.id="+id);
query.setHint("eclipselink.join-fetch", "me.equipmentHolders");
or
query.setHint("eclipselink.batch", "me.equipmentHolders");
(c)
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<ManagedElement> cq = qb.createQuery (ManagedElement.class);
cq.distinct (true);
Root<ManagedElement> meRoot = cq.from (ManagedElement.class);
meRoot.fetch ("equipmentHolders", JoinType.LEFT);
cq.where (qb.equal(meRoot.get("id"), id));
Query query = em.createQuery(cq);
query.getSingleResult();
With Eclipse IDE debug mode ,I can get the "equipmentHolders" of ManagedElement ,marked in red in the follow Figure.

Why I got a IndirectSet? Is this normal ? I want get HashSet not IndirectSet,Can someone help me ?
Thank you,Boyd.
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08842 seconds