Skip to content

Commit

Permalink
HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager i…
Browse files Browse the repository at this point in the history
…nto hibernate-core (have HibernateException extend JPA PersistenceException)
  • Loading branch information
sebersole committed May 6, 2016
1 parent f4d8a9d commit 8ef423a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
Expand Up @@ -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.
*
Expand Down
Expand Up @@ -1240,6 +1240,11 @@ private void fireRefresh(RefreshEvent event) {
}
}
catch (RuntimeException e) {
if ( !getSessionFactory().getSessionFactoryOptions().isJpaBootstrap() ) {
if ( e instanceof HibernateException ) {
throw e;
}
}
//including HibernateException
throw convert( e );
}
Expand All @@ -1258,6 +1263,12 @@ private void fireRefresh(Map refreshedAlready, RefreshEvent event) {
delayedAfterCompletion();
}
catch (RuntimeException e) {
if ( !getSessionFactory().getSessionFactoryOptions().isJpaBootstrap() ) {
if ( e instanceof HibernateException ) {
handlePersistenceException( (HibernateException) e );
throw e;
}
}
//including HibernateException
throw convert( e );
}
Expand Down
Expand Up @@ -325,21 +325,21 @@ public void testCountReturnValues() {
}
assertEquals( 1, count.longValue() );
}
catch (PersistenceException e) {
SQLGrammarException cause = assertTyping( SQLGrammarException.class, e.getCause() );
catch ( SQLGrammarException ex ) {
if ( ! getDialect().supportsTupleCounts() ) {
// expected
}
else {
throw e;
throw ex;
}
}
catch ( SQLGrammarException ex ) {
catch (PersistenceException e) {
SQLGrammarException cause = assertTyping( SQLGrammarException.class, e.getCause() );
if ( ! getDialect().supportsTupleCounts() ) {
// expected
}
else {
throw ex;
throw e;
}
}
finally {
Expand Down
Expand Up @@ -70,12 +70,12 @@ public void testTransactionTimeoutFailure() throws InterruptedException {
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();
}
Expand Down
Expand Up @@ -60,15 +60,12 @@ public void testInvalidOrm1() {
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 {
Expand Down

0 comments on commit 8ef423a

Please sign in to comment.