aspose file tools*
The moose likes Object Relational Mapping and the fly likes query.list() fails, query.iterate() doesn't Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "query.list() fails, query.iterate() doesn Watch "query.list() fails, query.iterate() doesn New topic

query.list() fails, query.iterate() doesn't

Dieter Quickfend
Ranch Hand

Joined: Aug 06, 2010
Posts: 359
So I have a simple case of two entities with a @ManyToMany implemented with a @CollectionOfElements. I do a simple query "select * from com.acme.entity.MyEntity where 1=1 order by column1 ASC, column2 ASC". This is a part of a rather generic application and works with no problems with a bunch of other entities, including the other side of the @ManyToMany, which has the same implementation of the @ElementCollection. The only real structural difference between these classes is that the ID is a String with the class where it fails, and a Long with the class where it works.

Now, I'm using JPA with vendor Hibernate, and whether I use em.getResultList or session.list, the result is the same:

After searching online and finding no answer to this problem, I noticed someone had the same issue and solved it by using "session.iterate()". I tried this and it worked without any issues.

So, my problem is solved, yes, but I'm not satisfied with that. I want to know WHY does 'list()' fail and iterate() work in this instance?

The only difference I can find between list() and iterate() is that iterate() reuses cached records whereas list() doesn't.

The entityManager is transaction scoped, the DAO is a Stateless EJB, and the method's transaction attribute is SUPPORTS.

If you need any more information, please ask. I am loath to put code on here as it doesn't really matter. I've tried many different combinations, but the em.getResultList() or session.list() always yield the same exception (above).

Oracle Certified Professional: Java SE 6 Programmer
Oracle Certified Expert: Java EE 6 Web Component Developer
Oracle Certified Expert: Java EE 6 Enterprise JavaBeans Developer
Dieter Quickfend
Ranch Hand

Joined: Aug 06, 2010
Posts: 359
For completeness' sake; this is the Collection definition in the JPA entity:

(codes are not unique)
I agree. Here's the link:
subject: query.list() fails, query.iterate() doesn't
Similar Threads
Exception when webservice is invoked
Error while calling webservice client from EJB3 SLB Local interface.
Column does not exist
want to integrate RMI with application on Client machine
Axis Error java.lang.NoClassDefFoundError: org/apache/commons/discovery/tools/DiscoverSingleton