Skip to content

Commit

Permalink
HHH-11570 - Hibernate Envers listeners fail because EntityManager is …
Browse files Browse the repository at this point in the history
…closed when using JPA/JTA/Hibernate 5.2.8/Envers
  • Loading branch information
dreab8 committed Mar 14, 2017
1 parent 197ea80 commit 31fbdbb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
Expand Up @@ -326,7 +326,7 @@ protected void cleanupOnClose() {
@Override
public void checkOpen(boolean markForRollbackIfClosed) {
if ( isClosed() ) {
if ( markForRollbackIfClosed ) {
if ( markForRollbackIfClosed && transactionCoordinator.isTransactionActive() ) {
markForRollbackOnly();
}
throw new IllegalStateException( "Session/EntityManager is closed" );
Expand All @@ -337,10 +337,6 @@ protected void checkOpenOrWaitingForAutoClose() {
if ( !waitingForAutoClose ) {
checkOpen();
}
else if ( factory.isClosed() ) {
markForRollbackOnly();
throw new IllegalStateException( "SessionFactory is closed" );
}
}

/**
Expand Down
Expand Up @@ -510,7 +510,7 @@ private void managedClose() {

@Override
public Connection connection() throws HibernateException {
checkOpen();
checkOpenOrWaitingForAutoClose();
return getJdbcCoordinator().getLogicalConnection().getPhysicalConnection();
}

Expand All @@ -531,7 +531,7 @@ public void reconnect(Connection conn) throws HibernateException {

@Override
public void setAutoClear(boolean enabled) {
checkOpen();
checkOpenOrWaitingForAutoClose();
autoClear = enabled;
}

Expand Down Expand Up @@ -1462,7 +1462,7 @@ public void forceFlush(EntityEntry entityEntry) throws HibernateException {

@Override
public List list(String query, QueryParameters queryParameters) throws HibernateException {
checkOpen();
checkOpenOrWaitingForAutoClose();
checkTransactionSynchStatus();
queryParameters.validateParameters();

Expand Down Expand Up @@ -1491,7 +1491,7 @@ public List list(String query, QueryParameters queryParameters) throws Hibernate

@Override
public int executeUpdate(String query, QueryParameters queryParameters) throws HibernateException {
checkOpen();
checkOpenOrWaitingForAutoClose();
checkTransactionSynchStatus();
queryParameters.validateParameters();
HQLQueryPlan plan = getQueryPlan( query, false );
Expand All @@ -1514,7 +1514,7 @@ public int executeUpdate(String query, QueryParameters queryParameters) throws H
public int executeNativeUpdate(
NativeSQLQuerySpecification nativeQuerySpecification,
QueryParameters queryParameters) throws HibernateException {
checkOpen();
checkOpenOrWaitingForAutoClose();
checkTransactionSynchStatus();
queryParameters.validateParameters();
NativeSQLQueryPlan plan = getNativeQueryPlan( nativeQuerySpecification );
Expand All @@ -1537,7 +1537,7 @@ public int executeNativeUpdate(

@Override
public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException {
checkOpen();
checkOpenOrWaitingForAutoClose();
checkTransactionSynchStatus();
queryParameters.validateParameters();

Expand All @@ -1560,7 +1560,7 @@ public Iterator iterate(String query, QueryParameters queryParameters) throws Hi

@Override
public ScrollableResultsImplementor scroll(String query, QueryParameters queryParameters) throws HibernateException {
checkOpen();
checkOpenOrWaitingForAutoClose();
checkTransactionSynchStatus();

HQLQueryPlan plan = queryParameters.getQueryPlan();
Expand Down Expand Up @@ -1754,7 +1754,7 @@ private FilterQueryPlan getFilterQueryPlan(

@Override
public List listFilter(Object collection, String filter, QueryParameters queryParameters) {
checkOpen();
checkOpenOrWaitingForAutoClose();
checkTransactionSynchStatus();
FilterQueryPlan plan = getFilterQueryPlan( collection, filter, queryParameters, false );
List results = Collections.EMPTY_LIST;
Expand All @@ -1775,7 +1775,7 @@ public List listFilter(Object collection, String filter, QueryParameters queryPa

@Override
public Iterator iterateFilter(Object collection, String filter, QueryParameters queryParameters) {
checkOpen();
checkOpenOrWaitingForAutoClose();
checkTransactionSynchStatus();
FilterQueryPlan plan = getFilterQueryPlan( collection, filter, queryParameters, true );
Iterator itr = plan.performIterate( queryParameters, this );
Expand Down Expand Up @@ -1820,7 +1820,7 @@ public ScrollableResultsImplementor scroll(Criteria criteria, ScrollMode scrollM
// TODO: Is this guaranteed to always be CriteriaImpl?
CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;

checkOpen();
checkOpenOrWaitingForAutoClose();
checkTransactionSynchStatus();

String entityName = criteriaImpl.getEntityOrClassName();
Expand Down Expand Up @@ -1857,7 +1857,7 @@ public List list(Criteria criteria) throws HibernateException {
}


checkOpen();
checkOpenOrWaitingForAutoClose();
// checkTransactionSynchStatus();

String[] implementors = getFactory().getMetamodel().getImplementors( criteriaImpl.getEntityOrClassName() );
Expand Down Expand Up @@ -2112,7 +2112,7 @@ public ProcedureCall createStoredProcedureCall(String procedureName, Class... re

@Override
public ScrollableResultsImplementor scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) {
checkOpen();
checkOpenOrWaitingForAutoClose();
// checkTransactionSynchStatus();

if ( log.isTraceEnabled() ) {
Expand All @@ -2136,7 +2136,7 @@ public ScrollableResultsImplementor scrollCustomQuery(CustomQuery customQuery, Q
// basically just an adapted copy of find(CriteriaImpl)
@Override
public List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) {
checkOpen();
checkOpenOrWaitingForAutoClose();
// checkTransactionSynchStatus();

if ( log.isTraceEnabled() ) {
Expand Down Expand Up @@ -2225,7 +2225,7 @@ private void throwTransientObjectException(Object object) throws HibernateExcept

@Override
public String guessEntityName(Object object) throws HibernateException {
checkOpen();
checkOpenOrWaitingForAutoClose();
return getEntityNameResolver().resolveEntityName( object );
}

Expand Down

0 comments on commit 31fbdbb

Please sign in to comment.