-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting a different connection handling mode and auto-close mod…
…e for non-injected sessions With this patch, hopefully people can safely use EntityManagerFactory.createEntityManager() and opening transactions manually? Signed-off-by: Yoann Rodière <yoann@hibernate.org>
- Loading branch information
Showing
4 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/session/JTASessionOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.quarkus.hibernate.orm.runtime.session; | ||
|
||
import org.hibernate.FlushMode; | ||
import org.hibernate.SessionBuilder; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; | ||
|
||
public class JTASessionOptions { | ||
private static final String KEY = JTASessionOptions.class.getName(); | ||
|
||
public static void init(SessionFactory sessionFactory) { | ||
SessionBuilder<?> options = sessionFactory.withOptions() | ||
.autoClose(true) // .owner() is deprecated as well, so it looks like we need to rely on deprecated code... | ||
.connectionHandlingMode( | ||
PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_BEFORE_TRANSACTION_COMPLETION) | ||
.flushMode(FlushMode.ALWAYS); | ||
sessionFactory.getProperties().put(KEY, options); | ||
} | ||
|
||
public static SessionBuilder<?> get(SessionFactory sessionFactory) { | ||
return (SessionBuilder<?>) sessionFactory.getProperties().get(KEY); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters