• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session FlushMode : AUTO Vs MANUAL

 
kri shan
Ranch Hand
Posts: 1479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which one(AUTO / MANUAL) is better for good performance and pros and cons of both ?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manual you are responsible for all flushing. Meaning nothing will be written to the database unless you specifically call flush in your code. Not really a responsibility I would want to have. Auto is nice because I trust Hibernate to flush at the right times, and get the right data that I expect. Yes you might have Hibernate flush more times than you want, but usually that occurs on misusing Sessions and having it do more work than one use case, and sometimes miss designing a use case.

Mark
 
kri shan
Ranch Hand
Posts: 1479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark, As per scenario our trasaction spans two classes(DAO's). Can i pass the same session to another DAO or create new session in another DAO? Here both(DAOs) are different table CRUD operations.
Can i commit at the end of the transaction or using different commit for each DAO?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kri shan:
Hi Mark, As per scenario our trasaction spans two classes(DAO's). Can i pass the same session to another DAO or create new session in another DAO? Here both(DAOs) are different table CRUD operations.
Can i commit at the end of the transaction or using different commit for each DAO?


This is what sessionFactory.getCurrentSession() does for you. You need that session to span two DAOs, getCurrentSession() will create a Session for you if one doesn't already exist. If one already exists, it returns that one. It stores the Session into the ThreadLocal. Check out the ThreadLocal javadocs for more information on how that works.

Mark
 
arulk pillai
Author
Ranch Hand
Posts: 3393
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



The more elegant way is to use it via Spring ORM support.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic