This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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).