HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager into hibernate-core (have HibernateException extend JPA PersistenceException)

This commit is contained in:
Steve Ebersole 2016-04-28 18:36:47 -05:00
parent f4d8a9d850
commit 8ef423a1b3
5 changed files with 26 additions and 18 deletions

View File

@ -6,17 +6,17 @@
*/
package org.hibernate;
import javax.persistence.PersistenceException;
/**
* The base exception type for Hibernate exceptions.
* <p/>
* Note that all {@link java.sql.SQLException SQLExceptions} will be wrapped in some form of
* {@link JDBCException}.
*
* @see JDBCException
*
* @author Gavin King
*/
public class HibernateException extends RuntimeException {
public class HibernateException extends PersistenceException {
/**
* Constructs a HibernateException using the given exception message.
*

View File

@ -1240,6 +1240,11 @@ public final class SessionImpl
}
}
catch (RuntimeException e) {
if ( !getSessionFactory().getSessionFactoryOptions().isJpaBootstrap() ) {
if ( e instanceof HibernateException ) {
throw e;
}
}
//including HibernateException
throw convert( e );
}
@ -1258,6 +1263,12 @@ public final class SessionImpl
delayedAfterCompletion();
}
catch (RuntimeException e) {
if ( !getSessionFactory().getSessionFactoryOptions().isJpaBootstrap() ) {
if ( e instanceof HibernateException ) {
handlePersistenceException( (HibernateException) e );
throw e;
}
}
//including HibernateException
throw convert( e );
}

View File

@ -325,6 +325,14 @@ public class CriteriaHQLAlignmentTest extends QueryTranslatorTestCase {
}
assertEquals( 1, count.longValue() );
}
catch ( SQLGrammarException ex ) {
if ( ! getDialect().supportsTupleCounts() ) {
// expected
}
else {
throw ex;
}
}
catch (PersistenceException e) {
SQLGrammarException cause = assertTyping( SQLGrammarException.class, e.getCause() );
if ( ! getDialect().supportsTupleCounts() ) {
@ -334,14 +342,6 @@ public class CriteriaHQLAlignmentTest extends QueryTranslatorTestCase {
throw e;
}
}
catch ( SQLGrammarException ex ) {
if ( ! getDialect().supportsTupleCounts() ) {
// expected
}
else {
throw ex;
}
}
finally {
t.rollback();
s.close();

View File

@ -70,12 +70,12 @@ public class TransactionTimeoutTest extends BaseCoreFunctionalTestCase {
session.persist( new Person( "Lukasz", "Antoniak" ) );
transaction.commit();
}
catch (PersistenceException e) {
assertTyping( TransactionException.class, e.getCause() );
}
catch (TransactionException e) {
// expected
}
catch (PersistenceException e) {
assertTyping( TransactionException.class, e.getCause() );
}
finally {
session.close();
}

View File

@ -60,15 +60,12 @@ public class OrmVersionTest {
hp.createContainerEntityManagerFactory( pui, Collections.EMPTY_MAP );
Assert.fail( "expecting 'invalid content' error" );
}
catch ( InvalidMappingException expected ) {
catch ( InvalidMappingException | AnnotationException expected ) {
// expected condition
}
catch ( PersistenceException expected ) {
// expected condition
}
catch (AnnotationException expected) {
// expected condition
}
}
public static class PersistenceUnitInfoImpl implements PersistenceUnitInfo {