• 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

Session FlushMode : AUTO Vs MANUAL

 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which one(AUTO / MANUAL) is better for good performance and pros and cons of both ?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 3473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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