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