HHH-13541 ExceptionConverter instance in AbstractSharedSessionContract should be lazily initialized

This commit is contained in:
Sanne Grinovero 2019-08-05 14:10:52 +01:00
parent 71fe4229b4
commit 8c228244de
4 changed files with 70 additions and 66 deletions

View File

@ -473,6 +473,12 @@ public interface SharedSessionContractImplementor
*/
LoadQueryInfluencers getLoadQueryInfluencers();
/**
* The converter associated to a Session might be lazily initialized: only invoke
* this getter when there is actual need to use it.
*
* @return the ExceptionConverter for this Session.
*/
ExceptionConverter getExceptionConverter();
/**

View File

@ -30,7 +30,6 @@ public class TransactionImpl implements TransactionImplementor {
private static final Logger LOG = CoreLogging.logger( TransactionImpl.class );
private final TransactionCoordinator transactionCoordinator;
private final ExceptionConverter exceptionConverter;
private final JpaCompliance jpaCompliance;
private final AbstractSharedSessionContract session;
@ -38,10 +37,8 @@ public class TransactionImpl implements TransactionImplementor {
public TransactionImpl(
TransactionCoordinator transactionCoordinator,
ExceptionConverter exceptionConverter,
AbstractSharedSessionContract session) {
this.transactionCoordinator = transactionCoordinator;
this.exceptionConverter = exceptionConverter;
this.jpaCompliance = session.getFactory().getSessionFactoryOptions().getJpaCompliance();
this.session = session;
@ -104,7 +101,7 @@ public class TransactionImpl implements TransactionImplementor {
internalGetTransactionDriverControl().commit();
}
catch (RuntimeException e) {
throw exceptionConverter.convertCommitException( e );
throw session.getExceptionConverter().convertCommitException( e );
}
}

View File

@ -147,7 +147,8 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
private Integer jdbcBatchSize;
protected transient ExceptionConverter exceptionConverter;
//Lazily initialized
private transient ExceptionConverter exceptionConverter;
private CriteriaCompiler criteriaCompiler;
@ -217,7 +218,6 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
.getService( TransactionCoordinatorBuilder.class )
.buildTransactionCoordinator( jdbcCoordinator, this );
}
exceptionConverter = new ExceptionConverterImpl( this );
}
protected void addSharedSessionTransactionObserver(TransactionCoordinator transactionCoordinator) {
@ -314,7 +314,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
}
catch ( HibernateException e ) {
if ( getFactory().getSessionFactoryOptions().isJpaBootstrap() ) {
throw this.exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
else {
throw e;
@ -436,7 +436,6 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
if ( this.currentHibernateTransaction == null ) {
this.currentHibernateTransaction = new TransactionImpl(
getTransactionCoordinator(),
getExceptionConverter(),
this
);
}
@ -557,7 +556,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return callback.executeOnConnection( connection );
}
catch (SQLException e) {
throw exceptionConverter.convert(
throw getExceptionConverter().convert(
e,
"Error creating contextual LOB : " + e.getMessage()
);
@ -644,7 +643,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return createNativeQuery( nativeQueryDefinition, true );
}
throw exceptionConverter.convert( new IllegalArgumentException( "No query defined for that name [" + name + "]" ) );
throw getExceptionConverter().convert( new IllegalArgumentException( "No query defined for that name [" + name + "]" ) );
}
protected QueryImplementor createQuery(NamedQueryDefinition queryDefinition) {
@ -737,7 +736,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
}
catch (RuntimeException e) {
markForRollbackOnly();
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -757,7 +756,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return (QueryImplementor<T>) criteriaCompiler().compile( (CompilableCriteria) criteriaQuery );
}
catch ( RuntimeException e ) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -768,7 +767,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return criteriaCompiler().compile( (CompilableCriteria) criteriaUpdate );
}
catch ( RuntimeException e ) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -779,7 +778,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return criteriaCompiler().compile( (CompilableCriteria) criteriaDelete );
}
catch ( RuntimeException e ) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -812,7 +811,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return query;
}
catch ( RuntimeException e ) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -833,7 +832,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return query;
}
catch ( RuntimeException e ) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -911,7 +910,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return (QueryImplementor<T>) createNativeQuery( nativeQueryDefinition, resultType );
}
throw exceptionConverter.convert( new IllegalArgumentException( "No query defined for that name [" + name + "]" ) );
throw getExceptionConverter().convert( new IllegalArgumentException( "No query defined for that name [" + name + "]" ) );
}
catch (RuntimeException e) {
throw !( e instanceof IllegalArgumentException ) ? new IllegalArgumentException( e ) : e;
@ -1029,7 +1028,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return query;
}
catch ( RuntimeException he ) {
throw exceptionConverter.convert( he );
throw getExceptionConverter().convert( he );
}
}
@ -1054,7 +1053,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return query;
}
catch ( RuntimeException he ) {
throw exceptionConverter.convert( he );
throw getExceptionConverter().convert( he );
}
}
@ -1069,7 +1068,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return createNativeQuery( nativeQueryDefinition, true );
}
throw exceptionConverter.convert( new IllegalArgumentException( "No query defined for that name [" + name + "]" ) );
throw getExceptionConverter().convert( new IllegalArgumentException( "No query defined for that name [" + name + "]" ) );
}
@Override
@ -1095,7 +1094,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return query;
}
catch ( RuntimeException he ) {
throw exceptionConverter.convert( he );
throw getExceptionConverter().convert( he );
}
}
@ -1161,7 +1160,10 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
}
@Override
public ExceptionConverter getExceptionConverter(){
public ExceptionConverter getExceptionConverter() {
if ( exceptionConverter == null ) {
exceptionConverter = new ExceptionConverterImpl( this );
}
return exceptionConverter;
}
@ -1234,8 +1236,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
.buildTransactionCoordinator( jdbcCoordinator, this );
entityNameResolver = new CoordinatingEntityNameResolver( factory, interceptor );
exceptionConverter = new ExceptionConverterImpl( this );
this.disallowOutOfTransactionUpdateOperations = !getFactory().getSessionFactoryOptions().isAllowOutOfTransactionUpdateOperations();
}
}

View File

@ -370,7 +370,7 @@ public final class SessionImpl
internalClear();
}
catch (RuntimeException e) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -472,7 +472,7 @@ public final class SessionImpl
return !isClosed();
}
catch (HibernateException he) {
throw exceptionConverter.convert( he );
throw getExceptionConverter().convert( he );
}
}
@ -789,17 +789,17 @@ public final class SessionImpl
}
}
catch (MappingException e) {
throw exceptionConverter.convert( new IllegalArgumentException( e.getMessage() ) );
throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage() ) );
}
catch (RuntimeException e) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
finally {
try {
checkNoUnresolvedActionsAfterOperation();
}
catch (RuntimeException e) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
}
@ -813,10 +813,10 @@ public final class SessionImpl
}
}
catch ( MappingException e ) {
throw exceptionConverter.convert( new IllegalArgumentException( e.getMessage() ) ) ;
throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage() ) ) ;
}
catch ( RuntimeException e ) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
finally {
delayedAfterCompletion();
@ -891,14 +891,14 @@ public final class SessionImpl
checkNoUnresolvedActionsAfterOperation();
}
catch ( ObjectDeletedException sse ) {
throw exceptionConverter.convert( new IllegalArgumentException( sse ) );
throw getExceptionConverter().convert( new IllegalArgumentException( sse ) );
}
catch ( MappingException e ) {
throw exceptionConverter.convert( new IllegalArgumentException( e.getMessage(), e ) );
throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage(), e ) );
}
catch ( RuntimeException e ) {
//including HibernateException
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
return event.getResult();
@ -912,14 +912,14 @@ public final class SessionImpl
}
}
catch ( ObjectDeletedException sse ) {
throw exceptionConverter.convert( new IllegalArgumentException( sse ) );
throw getExceptionConverter().convert( new IllegalArgumentException( sse ) );
}
catch ( MappingException e ) {
throw exceptionConverter.convert( new IllegalArgumentException( e.getMessage(), e ) );
throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage(), e ) );
}
catch ( RuntimeException e ) {
//including HibernateException
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
finally {
delayedAfterCompletion();
@ -1000,14 +1000,14 @@ public final class SessionImpl
}
}
catch ( ObjectDeletedException sse ) {
throw exceptionConverter.convert( new IllegalArgumentException( sse ) );
throw getExceptionConverter().convert( new IllegalArgumentException( sse ) );
}
catch ( MappingException e ) {
throw exceptionConverter.convert( new IllegalArgumentException( e.getMessage(), e ) );
throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage(), e ) );
}
catch ( RuntimeException e ) {
//including HibernateException
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
finally {
delayedAfterCompletion();
@ -1022,14 +1022,14 @@ public final class SessionImpl
}
}
catch ( ObjectDeletedException sse ) {
throw exceptionConverter.convert( new IllegalArgumentException( sse ) );
throw getExceptionConverter().convert( new IllegalArgumentException( sse ) );
}
catch ( MappingException e ) {
throw exceptionConverter.convert( new IllegalArgumentException( e.getMessage(), e ) );
throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage(), e ) );
}
catch ( RuntimeException e ) {
//including HibernateException
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
finally {
delayedAfterCompletion();
@ -1373,7 +1373,7 @@ public final class SessionImpl
}
}
//including HibernateException
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
finally {
delayedAfterCompletion();
@ -1388,7 +1388,7 @@ public final class SessionImpl
}
}
catch (RuntimeException e) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
finally {
delayedAfterCompletion();
@ -1496,7 +1496,7 @@ public final class SessionImpl
delayedAfterCompletion();
}
catch ( RuntimeException e ) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -2152,7 +2152,7 @@ public final class SessionImpl
throw new IllegalArgumentException( e.getMessage(), e );
}
catch (RuntimeException e) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -2206,7 +2206,7 @@ public final class SessionImpl
throw new IllegalArgumentException( e.getMessage(), e );
}
catch (RuntimeException e) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -3491,11 +3491,11 @@ public final class SessionImpl
delete( entity );
}
catch (MappingException e) {
throw exceptionConverter.convert( new IllegalArgumentException( e.getMessage(), e ) );
throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage(), e ) );
}
catch ( RuntimeException e ) {
//including HibernateException
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -3555,7 +3555,7 @@ public final class SessionImpl
throw new IllegalArgumentException( e.getMessage(), e );
}
catch ( MappingException | TypeMismatchException | ClassCastException e ) {
throw exceptionConverter.convert( new IllegalArgumentException( e.getMessage(), e ) );
throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage(), e ) );
}
catch ( JDBCException e ) {
if ( accessTransaction().getRollbackOnly() ) {
@ -3563,11 +3563,11 @@ public final class SessionImpl
return null;
}
else {
throw exceptionConverter.convert( e, lockOptions );
throw getExceptionConverter().convert( e, lockOptions );
}
}
catch ( RuntimeException e ) {
throw exceptionConverter.convert( e, lockOptions );
throw getExceptionConverter().convert( e, lockOptions );
}
finally {
getLoadQueryInfluencers().getEffectiveEntityGraph().clear();
@ -3612,10 +3612,10 @@ public final class SessionImpl
return byId( entityClass ).getReference( (Serializable) primaryKey );
}
catch ( MappingException | TypeMismatchException | ClassCastException e ) {
throw exceptionConverter.convert( new IllegalArgumentException( e.getMessage(), e ) );
throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage(), e ) );
}
catch ( RuntimeException e ) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -3638,7 +3638,7 @@ public final class SessionImpl
buildLockRequest( lockOptions ).lock( entity );
}
catch (RuntimeException e) {
throw exceptionConverter.convert( e, lockOptions );
throw getExceptionConverter().convert( e, lockOptions );
}
}
@ -3664,7 +3664,7 @@ public final class SessionImpl
setCacheMode( refreshCacheMode );
if ( !contains( entity ) ) {
throw exceptionConverter.convert( new IllegalArgumentException( "Entity not managed" ) );
throw getExceptionConverter().convert( new IllegalArgumentException( "Entity not managed" ) );
}
if ( lockModeType != null ) {
@ -3680,10 +3680,10 @@ public final class SessionImpl
}
}
catch (MappingException e) {
throw exceptionConverter.convert( new IllegalArgumentException( e.getMessage(), e ) );
throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage(), e ) );
}
catch (RuntimeException e) {
throw exceptionConverter.convert( e, lockOptions );
throw getExceptionConverter().convert( e, lockOptions );
}
finally {
setCacheMode( previousCacheMode );
@ -3697,7 +3697,7 @@ public final class SessionImpl
evict( entity );
}
catch (RuntimeException e) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -3710,7 +3710,7 @@ public final class SessionImpl
}
if ( !contains( entity ) ) {
throw exceptionConverter.convert( new IllegalArgumentException( "entity not in the persistence context" ) );
throw getExceptionConverter().convert( new IllegalArgumentException( "entity not in the persistence context" ) );
}
return LockModeTypeHelper.getLockModeType( getCurrentLockMode( entity ) );
@ -3759,7 +3759,7 @@ public final class SessionImpl
return memento.makeProcedureCall( this );
}
catch ( RuntimeException e ) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -3769,7 +3769,7 @@ public final class SessionImpl
return createStoredProcedureCall( procedureName );
}
catch ( RuntimeException e ) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -3779,7 +3779,7 @@ public final class SessionImpl
return createStoredProcedureCall( procedureName, resultClasses );
}
catch ( RuntimeException e ) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -3795,7 +3795,7 @@ public final class SessionImpl
}
}
catch ( RuntimeException e ) {
throw exceptionConverter.convert( e );
throw getExceptionConverter().convert( e );
}
}
@ -3820,7 +3820,7 @@ public final class SessionImpl
throw new TransactionRequiredException( e.getMessage() );
}
catch (HibernateException he) {
throw exceptionConverter.convert( he );
throw getExceptionConverter().convert( he );
}
}