From 8ef423a1b3bd315724358513162a94bbba4f8822 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 28 Apr 2016 18:36:47 -0500 Subject: [PATCH] HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager into hibernate-core (have HibernateException extend JPA PersistenceException) --- .../java/org/hibernate/HibernateException.java | 6 +++--- .../java/org/hibernate/internal/SessionImpl.java | 11 +++++++++++ .../test/hql/CriteriaHQLAlignmentTest.java | 16 ++++++++-------- .../test/tm/TransactionTimeoutTest.java | 6 +++--- .../hibernate/jpa/test/jee/OrmVersionTest.java | 5 +---- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/HibernateException.java b/hibernate-core/src/main/java/org/hibernate/HibernateException.java index 5d8895de7c..7d3d1a8e10 100644 --- a/hibernate-core/src/main/java/org/hibernate/HibernateException.java +++ b/hibernate-core/src/main/java/org/hibernate/HibernateException.java @@ -6,17 +6,17 @@ */ package org.hibernate; +import javax.persistence.PersistenceException; + /** * The base exception type for Hibernate exceptions. *

* 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. * diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 6acefeb068..8320e48ab8 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -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 ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/CriteriaHQLAlignmentTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/CriteriaHQLAlignmentTest.java index 1053b12150..de44da7524 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/CriteriaHQLAlignmentTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/CriteriaHQLAlignmentTest.java @@ -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(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/tm/TransactionTimeoutTest.java b/hibernate-core/src/test/java/org/hibernate/test/tm/TransactionTimeoutTest.java index 4d134c7901..1025355594 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/tm/TransactionTimeoutTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/tm/TransactionTimeoutTest.java @@ -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(); } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/jee/OrmVersionTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/jee/OrmVersionTest.java index 8b4f51409b..7ea59491b2 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/jee/OrmVersionTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/jee/OrmVersionTest.java @@ -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 {