• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session.clear when to use

 
nimo frey
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?
 
Benjamin Winterberg
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic