• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

fetch lazy collection without initialize

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a collection with lazy fetch and want to fetch the collection within a session:

So I tried this, but that does not hit the database to fetch the collection:




Why does 1.way not work?

How would I do the "Hibernate.initialize" normally in JPA 2-standard?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess is you have a collection of proxies until you call a method on those proxies (I'm assuming the implicit call to toString() is the method). Can't say for sue without reading the Hibernate source. Just out of curiosity, why would you ever need to do 1? Do you have occasions where you want to return data from the database and do nothing with it?


How would I do the "Hibernate.initialize" normally in JPA 2-standard?


You can't, but again I can't think of a case where you might need to. Am I missing something?
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to fetch my collections via a condition, so annotating my collection with FetchType.EAGER is not usefull in this case.

I only want to touch the collection so it is fetched - the collection is not used within the same transaction so it automatically gets unmanaged - which is what I want!
(I also cannot use a separate query with "left join fetch" as there are more than one collections..)



so I use this, which works fine in my case:




However, Hibernate.initialize is not JPA-Standard-conform.

However, it works;) thanks.

 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I want to fetch my collections via a condition, so annotating my collection with FetchType.EAGER is not usefull in this case.


Any reason you don't just eagerly fetch your query based on the same condition?
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Any reason you don't just eagerly fetch your query based on the same condition?



I cannot use a separate query with "left join fetch" as there are more than one collections which I want to fetch:



It is far faster to initialize the collections via



instead of using the above query.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic