• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

fetch lazy collection without initialize  RSS feed

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!