From 22f858c68bd8b4cb2ad10e74114a5e0f3c02da78 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Mon, 1 Feb 2021 22:10:24 +0000 Subject: [PATCH] HHH-14428 Could avoid allocating an org.hibernate.internal.SessionFactoryImpl when no options are set --- .../java/org/hibernate/internal/SessionFactoryImpl.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 1c3ab0e33f..d02bd459d3 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -197,6 +197,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor { private final transient FastSessionServices fastSessionServices; private final transient SessionBuilder defaultSessionOpenOptions; private final transient SessionBuilder temporarySessionOpenOptions; + private final transient StatelessSessionBuilder defaultStatelessOptions; public SessionFactoryImpl( final MetadataImplementor metadata, @@ -381,6 +382,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor { this.defaultSessionOpenOptions = createDefaultSessionOpenOptionsIfPossible(); this.temporarySessionOpenOptions = this.defaultSessionOpenOptions == null ? null : buildTemporarySessionOpenOptions(); + this.defaultStatelessOptions = this.defaultSessionOpenOptions == null ? null : withStatelessOptions(); this.fastSessionServices = new FastSessionServices( this ); this.observer.sessionFactoryCreated( this ); @@ -503,7 +505,12 @@ public class SessionFactoryImpl implements SessionFactoryImplementor { } public StatelessSession openStatelessSession() { - return withStatelessOptions().openStatelessSession(); + if ( this.defaultStatelessOptions != null ) { + return this.defaultStatelessOptions.openStatelessSession(); + } + else { + return withStatelessOptions().openStatelessSession(); + } } public StatelessSession openStatelessSession(Connection connection) {