[hibernate-dev] Does any RuntimeException cause a transaction rollback?

Emmanuel Bernard emmanuel at hibernate.org
Mon Feb 22 12:53:35 EST 2010


Yes I think that's the correct behavior with a small twist.
Every non HibernateException and PersistenceException should mark for rollback.
HibernateException and PersistenceException have different rules that are implemented somewhere nearby.

On 22 févr. 2010, at 18:47, Hardy Ferentschik wrote:

> Hi,
> 
> I was just looking at HHH-4676 - "Any interceptor exception (RTE) should  
> mark the tx for rollback"
> and was wondering whether we can generally say that in JPA any  
> RuntimeException will mark the current
> transaction for a rollback.
> 
> Currently we have this in AbstractEntityManagerImpl:
> 
> 
> 	public RuntimeException convert(RuntimeException e) {
> 		RuntimeException result = e;
> 		if ( e instanceof HibernateException ) {
> 			result = convert( (HibernateException) e );
> 		}
> 		else if (e instanceof ConstraintViolationException) {
> 			markAsRollback();
> 		}
> 		//if any RT exception should mark the tx for rollback, convert the last  
> else if into a else
> 		return result;
> 	}
> 
> 
> 
> Should this be changed to:
> 
> 
> 	public RuntimeException convert(RuntimeException e) {
> 		RuntimeException result = e;
> 		if ( e instanceof HibernateException ) {
> 			result = convert( ( HibernateException ) e, null );
> 		}
> 		else {
> 			markAsRollback();
> 		}
> 		return result;
> 	}
> 
> Meaning all RuntimeExceptions will mark the current transaction for  
> rollback? Any comments?
> 
> --Hardy
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev





More information about the hibernate-dev mailing list