• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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

 
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Dieter Quickfend
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For completeness' sake; this is the Collection definition in the JPA entity:

(codes are not unique)
 
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic