-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Transaction question
PostPosted: Tue Feb 22, 2005 7:37 pm 
Newbie

Joined: Mon Feb 07, 2005 7:57 pm
Posts: 9
Hibernate version: 2.1.7

Hello there. My base class HibernateDAO (the ancestor for every DAO in my domain model) has this insert method:


Code:
public Serializable insert(Entity pojo) throws PersistenceException {
      Session session = HibernateUtil.getSession();
      Serializable s;
      Transaction tx = null;
      try {
         tx = session.beginTransaction();
         s = session.save(pojo);
         tx.commit();
      } catch (HibernateException e) {
         try {
            tx.rollback();
         } catch (HibernateException e1) {
            throw new RuntimeException(e1);
         }
         logger.error(e);
         throw new PersistenceException(e,"com.rhnet.error.persistence.insert");
         
      }finally{
         HibernateUtil.closeSession();
      }
      return s;


HibernateUtil was shameless copied from Hibernate in Action ...

My question is, this method will commit after every successful insert in the database, now, if I have a collection of pojos to be persisted and I must have an atomic insertion, since this method comits after every insert, it will fail to rollback a transaction if n item of the collection fails won't it? What would be the solution create another method that receives a collection and iterate through it?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 7:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Yes


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.