Skip to content

Commit 22f858c

Browse files
committed
HHH-14428 Could avoid allocating an org.hibernate.internal.SessionFactoryImpl when no options are set
1 parent 15d418c commit 22f858c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
197197
private final transient FastSessionServices fastSessionServices;
198198
private final transient SessionBuilder defaultSessionOpenOptions;
199199
private final transient SessionBuilder temporarySessionOpenOptions;
200+
private final transient StatelessSessionBuilder defaultStatelessOptions;
200201

201202
public SessionFactoryImpl(
202203
final MetadataImplementor metadata,
@@ -381,6 +382,7 @@ public void sessionFactoryClosed(SessionFactory factory) {
381382

382383
this.defaultSessionOpenOptions = createDefaultSessionOpenOptionsIfPossible();
383384
this.temporarySessionOpenOptions = this.defaultSessionOpenOptions == null ? null : buildTemporarySessionOpenOptions();
385+
this.defaultStatelessOptions = this.defaultSessionOpenOptions == null ? null : withStatelessOptions();
384386
this.fastSessionServices = new FastSessionServices( this );
385387

386388
this.observer.sessionFactoryCreated( this );
@@ -503,7 +505,12 @@ public StatelessSessionBuilder withStatelessOptions() {
503505
}
504506

505507
public StatelessSession openStatelessSession() {
506-
return withStatelessOptions().openStatelessSession();
508+
if ( this.defaultStatelessOptions != null ) {
509+
return this.defaultStatelessOptions.openStatelessSession();
510+
}
511+
else {
512+
return withStatelessOptions().openStatelessSession();
513+
}
507514
}
508515

509516
public StatelessSession openStatelessSession(Connection connection) {

0 commit comments

Comments
 (0)