Results 1 to 3 of 3

Thread: How to call many getHibernateTemplate().save() in one single transaction

  1. #1
    Join Date
    Mar 2010
    Posts
    11

    Default How to call many getHibernateTemplate().save() in one single transaction

    How to ensure more than one getHibernateTemplate().save() to be executed in one single transaction.

  2. #2
    Join Date
    May 2008
    Posts
    153

    Default

    There are many ways. Usually you have a DAO class annotated with @Transactional. As long as you make sure that the @Transactional is picked up by spring (and associated with the DAO class via transactional proxy), your hibernate code will run in a transaction. Also make sure you are using a transaction manager compatible with hibernate (i.e. read the javdoc for your transaction manager)

    Code:
    @Transactional
    public void saveStuff() {
      getHiberanteTemplate().save();
      getHiberanteTemplate().save();
      getHiberanteTemplate().save();
      ...
    }

  3. #3
    Join Date
    Mar 2010
    Posts
    11

    Default

    Thanks for your reply.

    I have configured eventListeners to log any database operation. Within my DAO method, I am actually inserting one record (INSERT operation is getting logged correctly), then I am updating that record (inside the same method) and the event listener is throwing an exception like "could not load entity with identifier ...". So my record is getting updated correctly, but the update is not logged correctly. (I have configured the @Transactional )

Posting Permissions

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