Announcement Announcement Module
Collapse
No announcement yet.
How to call many getHibernateTemplate().save() in one single transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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();
      ...
    }

    Comment


    • #3
      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 )

      Comment

      Working...
      X