Results 1 to 2 of 2

Thread: Hibernate Transactions

  1. #1

    Default Hibernate Transactions

    Hello,

    I've been investigating using spring's transaction annotations with hibernate. Right now we're using the hibernate threadlocal design pattern with an in house filter that handles closing hibernate sessions without using spring's transactionManager.
    In some places in our code we explicitly commit to generate a primary key because subsequent processing depends on it.

    So my question is if I implement OpenSessionInViewFilter, or the equivalent interceptor, and get my hibernate session via the SssionFactoryUtils can I still call session.beginTransaction.commit() in my dao's without any adverse affects? Will that call commit on spring's transactionManager or will that be a different transaction?

    thanks,
    Michael

  2. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    Michael,

    The OSIV filters/interceptors are completely separate from the transaction management interceptors. Our OSIV code simply starts and closes sessions. the TX interceptors obviously take care of managing the transactions.

    So, you can still use OSIV and begin/end transactions yourself, but you probably don't want to do this when using Spring TX interceptors.

    However, for your particular use case you should consider using flush() rather than commiting the transaction just to get the ID. If you were to use HibernateTemplate you can call HibernateTemplate.flush() to send all outstanding changes to the DB and update any IDs *without* having to commit the transaction.

    Rob
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

Similar Threads

  1. Replies: 2
    Last Post: Aug 11th, 2005, 09:22 AM
  2. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  3. Replies: 0
    Last Post: Jun 21st, 2005, 08:09 AM
  4. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  5. Replies: 7
    Last Post: Aug 21st, 2004, 03:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •