Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

session.clear when to use

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I fetch a large dataset via a hql and after fetching, I do a session.clear.

Now my question: Makes the session.clear any sense (performance, memory)
and what disadvantageous I have, when using session.clear in this scenario:



thanks in advance.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is, when I do a query and returns the result via list, does Hibernate stores all the query results into its first/second(?)-level-cache?

If yes, then session.clear() in this scenario makes sense, or?
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate puts all entities into the first level cache which is bound to the session. Session.clear() makes sense if you are doing batch processing (see chapter 13 in reference documentation) or if you are using as session for a long time without ever closing it. The latter is not recommended. Normally the session should be bound to the transaction and be closed on commit(). But there could be other scenarios where you want a session to be active for a longer time.

Normally you dont have to clear() the session. The session will automatically be cleared on close.
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic