Browse Source

Align currentStatelessSession() implementation with currentSession()

See gh-7184
pull/35641/head
Juergen Hoeller 2 months ago
parent
commit
b4dcb36b21
  1. 9
      spring-orm/src/main/java/org/springframework/orm/jpa/hibernate/SpringSessionContext.java

9
spring-orm/src/main/java/org/springframework/orm/jpa/hibernate/SpringSessionContext.java

@ -171,9 +171,6 @@ public class SpringSessionContext implements CurrentSessionContext { @@ -171,9 +171,6 @@ public class SpringSessionContext implements CurrentSessionContext {
* @return the current StatelessSession
*/
public static StatelessSession currentStatelessSession(SessionFactory sessionFactory) {
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
throw new HibernateException("Could not obtain transaction-synchronized Session for current thread");
}
Object value = TransactionSynchronizationManager.getResource(sessionFactory);
if (value instanceof StatelessSession statelessSession) {
return statelessSession;
@ -185,6 +182,8 @@ public class SpringSessionContext implements CurrentSessionContext { @@ -185,6 +182,8 @@ public class SpringSessionContext implements CurrentSessionContext {
}
holder = sessionHolder;
}
if (TransactionSynchronizationManager.isSynchronizationActive()) {
StatelessSession session = sessionFactory.openStatelessSession(determineConnection(sessionFactory, holder));
if (holder != null) {
holder.setStatelessSession(session);
@ -194,6 +193,10 @@ public class SpringSessionContext implements CurrentSessionContext { @@ -194,6 +193,10 @@ public class SpringSessionContext implements CurrentSessionContext {
}
return session;
}
else {
throw new HibernateException("Could not obtain transaction-synchronized Session for current thread");
}
}
private static void bindSessionHolder(SessionFactory sessionFactory, SessionHolder holder) {
TransactionSynchronizationManager.registerSynchronization(

Loading…
Cancel
Save