text: Eclipse Community Forums - RDF feed Eclipse Community Forums eclipselink.join-fetch not work at all <![CDATA[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. ]]> Boyd Pang 2011-06-28T07:12:39-00:00 Re: eclipselink.join-fetch not work at all <![CDATA[I used spring3.1.0M1 and Eclipselink2.3.0.v20110604-r9504,and in the documents of spring I found the changes infomation as follows: Changes in version 3.0.4 (2010-08-19) ------------------------------------- * support for Hibernate Core 3.6, Hibernate Validator 4.1, EclipseLink 2.1, EHCache 2.2 Changes in version 3.0.3 (2010-06-15) ------------------------------------- * Spring autodetects JodaTime 1.3 or higher (as required), ignoring older JodaTime versions * clarified that Spring's Jackson support requires Jackson 1.3 or higher * JPA 2.0 support tested and supported with Hibernate 3.5.2 and OpenJPA 2.0.0 GA as well I was confused by this problem for a long time,hope someone help me. Thank you very much,Boyd. ]]> Boyd Pang 2011-06-28T09:47:36-00:00 Re: eclipselink.join-fetch not work at all <![CDATA[JPA requires that you use the collection interfaces Collection, List, Set or Map to allow the JPA provider to provide optimizations just as LAZY loading. It should not matter what type of Set it is, just use the Set interface. If you really want a HashSet for some specific purpose, you can define a getFooAsHashSet method that returns new HashSet(this.foo). If you use EAGER, then by default EclipseLink will allow you to use an implementation class, but this is not possible with LAZY. EclipseLink will use an instance of IndirectSet (which contains a HashSet) for any LAZY field, this does not mean the set has not been read, just that it has the potential to be LAZY. In general in Java it is best to use the collection interfaces in your code. Why do you want a HashSet?]]> James Sutherland 2011-06-28T17:31:16-00:00 Re: eclipselink.join-fetch not work at all <![CDATA[Thank you very much James. I am a new one to Eclipselink,and I didn't understand lazy loading very well before.I thought that if the data fetched sucessfully,the eager loading and lazy loading will have a same data structure(that is a HashSet) ,that's why I said I need a HashSet. Now I understand the lazy loading，if I set the hint "eclipselink.join-fetch",the data were fetched successfully indeed,although contained in a IndirectSet. Once again, thank you very much. ]]> Boyd Pang 2011-06-29T01:21:49-00:00 (no subject) <![CDATA[James, Is there any way to know that the IndirectSet is instantiated(tha) yet ? That is data have been fetcted from db.]]> Boyd Pang 2011-06-30T07:17:05-00:00 Re: (no subject) <![CDATA[You can call the isInstantiated() method.]]> James Sutherland 2011-06-30T14:12:56-00:00