From 23aa8875d804f5caeb2faa55b8cfd52eee3534ab Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 2 May 2012 14:14:34 -0500 Subject: [PATCH] HHH-7265 - ConcurrentModificationException in SynchronizationRegistryImpl.notifySynchronizationsAfterTransactionCompletion due to SynchronizationRegistryImpl.clearSynchronizations clearing SynchronizationRegistryImpl.synchronizations --- .../src/main/java/org/hibernate/SessionBuilder.java | 4 ++++ .../src/main/java/org/hibernate/SharedSessionBuilder.java | 4 ++++ .../hibernate/engine/spi/SessionBuilderImplementor.java | 1 - .../hibernate/engine/spi/SessionFactoryImplementor.java | 3 +++ .../java/org/hibernate/{ => engine/spi}/SessionOwner.java | 7 ++++--- .../java/org/hibernate/internal/SessionFactoryImpl.java | 2 +- .../src/main/java/org/hibernate/internal/SessionImpl.java | 8 ++++---- .../main/java/org/hibernate/ejb/EntityManagerImpl.java | 6 +----- 8 files changed, 21 insertions(+), 14 deletions(-) rename hibernate-core/src/main/java/org/hibernate/{ => engine/spi}/SessionOwner.java (88%) diff --git a/hibernate-core/src/main/java/org/hibernate/SessionBuilder.java b/hibernate-core/src/main/java/org/hibernate/SessionBuilder.java index e69dff22d3..ace9310773 100644 --- a/hibernate-core/src/main/java/org/hibernate/SessionBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/SessionBuilder.java @@ -93,7 +93,11 @@ public interface SessionBuilder { * @param autoClose Should the session be automatically closed * * @return {@code this}, for method chaining + * + * @deprecated Only integrations can specify autoClosing behavior of individual sessions. See + * {@link org.hibernate.engine.spi.SessionOwner} */ + @Deprecated public SessionBuilder autoClose(boolean autoClose); /** diff --git a/hibernate-core/src/main/java/org/hibernate/SharedSessionBuilder.java b/hibernate-core/src/main/java/org/hibernate/SharedSessionBuilder.java index b06e5599fe..dfadd06a3e 100644 --- a/hibernate-core/src/main/java/org/hibernate/SharedSessionBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/SharedSessionBuilder.java @@ -63,7 +63,11 @@ public interface SharedSessionBuilder extends SessionBuilder { * Signifies that the autoClose flag from the original session should be used to create the new session * * @return {@code this}, for method chaining + * + * @deprecated For same reasons as {@link SessionBuilder#autoClose(boolean)} was deprecated. However, shared + * session builders can use {@link #autoClose(boolean)} since they do not "inherit" the owner. */ + @Deprecated public SharedSessionBuilder autoClose(); /** diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionBuilderImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionBuilderImplementor.java index 8544ebc198..ff2244dcfa 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionBuilderImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionBuilderImplementor.java @@ -24,7 +24,6 @@ package org.hibernate.engine.spi; import org.hibernate.SessionBuilder; -import org.hibernate.SessionOwner; /** * Defines the internal contract between the SessionBuilder and other parts of diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java index cb912c23c4..c01e229770 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java @@ -66,6 +66,9 @@ import org.hibernate.type.TypeResolver; * @author Gavin King */ public interface SessionFactoryImplementor extends Mapping, SessionFactory { + @Override + public SessionBuilderImplementor withOptions(); + /** * Retrieve the {@link Type} resolver associated with this factory. * diff --git a/hibernate-core/src/main/java/org/hibernate/SessionOwner.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionOwner.java similarity index 88% rename from hibernate-core/src/main/java/org/hibernate/SessionOwner.java rename to hibernate-core/src/main/java/org/hibernate/engine/spi/SessionOwner.java index bdf7b671f3..6cde77de8d 100644 --- a/hibernate-core/src/main/java/org/hibernate/SessionOwner.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionOwner.java @@ -21,12 +21,14 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate; +package org.hibernate.engine.spi; /** - * The contract for a session owner. + * The contract for a Session owner. Typically this is something that wraps the Session. * * @author Gail Badner + * + * @see SessionBuilderImplementor#owner */ public interface SessionOwner { /** @@ -35,5 +37,4 @@ public interface SessionOwner { * @return {@literal true}/{@literal false} appropriately. */ public boolean shouldAutoCloseSession(); - } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index 6185d717b5..34b829f3d9 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -59,7 +59,7 @@ import org.hibernate.Session; import org.hibernate.SessionBuilder; import org.hibernate.SessionFactory; import org.hibernate.SessionFactoryObserver; -import org.hibernate.SessionOwner; +import org.hibernate.engine.spi.SessionOwner; import org.hibernate.StatelessSession; import org.hibernate.StatelessSessionBuilder; import org.hibernate.TypeHelper; 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 ea4b0c1e33..6d0a6dc53c 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -73,7 +73,7 @@ import org.hibernate.ScrollableResults; import org.hibernate.Session; import org.hibernate.SessionBuilder; import org.hibernate.SessionException; -import org.hibernate.SessionOwner; +import org.hibernate.engine.spi.SessionOwner; import org.hibernate.SharedSessionBuilder; import org.hibernate.SimpleNaturalIdLoadAccess; import org.hibernate.Transaction; @@ -531,11 +531,11 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc if ( isClosed() ) { return false; } - else if ( isAutoCloseSessionEnabled() ) { - return true; + else if ( sessionOwner != null ) { + return sessionOwner.shouldAutoCloseSession(); } else { - return sessionOwner != null && sessionOwner.shouldAutoCloseSession(); + return isAutoCloseSessionEnabled(); } } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/EntityManagerImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/EntityManagerImpl.java index e7dcc0d3d3..c245ca74f2 100755 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/EntityManagerImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/EntityManagerImpl.java @@ -27,21 +27,17 @@ import java.util.Map; import javax.persistence.PersistenceContextType; import javax.persistence.PersistenceException; import javax.persistence.spi.PersistenceUnitTransactionType; -import javax.transaction.Synchronization; import org.jboss.logging.Logger; import org.hibernate.HibernateException; import org.hibernate.Interceptor; import org.hibernate.Session; -import org.hibernate.SessionBuilder; -import org.hibernate.SessionOwner; +import org.hibernate.engine.spi.SessionOwner; import org.hibernate.annotations.common.util.ReflectHelper; -import org.hibernate.cfg.Environment; import org.hibernate.ejb.internal.EntityManagerMessageLogger; import org.hibernate.engine.spi.SessionBuilderImplementor; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.internal.SessionFactoryImpl; /** * Hibernate implementation of {@link javax.persistence.EntityManager}.