From c60fbc20ec0e093cd72f5e3ce873c65d42589913 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Thu, 9 Jun 2022 18:56:08 +0200 Subject: [PATCH] documentation for hibernate.enable_lazy_load_no_trans --- .../main/asciidoc/userguide/appendices/Configurations.adoc | 6 +++--- .../src/main/java/org/hibernate/cfg/AvailableSettings.java | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/documentation/src/main/asciidoc/userguide/appendices/Configurations.adoc b/documentation/src/main/asciidoc/userguide/appendices/Configurations.adoc index c9f9763337..3da3a840ef 100644 --- a/documentation/src/main/asciidoc/userguide/appendices/Configurations.adoc +++ b/documentation/src/main/asciidoc/userguide/appendices/Configurations.adoc @@ -636,11 +636,11 @@ Enables Hibernate to use JDBC2 scrollable resultsets. This property is only rele Allows Hibernate to use JDBC3 `PreparedStatement.getGeneratedKeys()` to retrieve natively-generated keys after insert. You need the JDBC3+ driver and JRE1.4+. Disable this property if your driver has problems with the Hibernate identifier generators. By default, it tries to detect the driver capabilities from connection metadata. `*hibernate.enable_lazy_load_no_trans*` (e.g. `true` or `false` (default value)):: -Initialize Lazy Proxies or Collections outside a given Transactional Persistence Context. +Allows a detached proxy or lazy collection to be fetched even when not associated with an open session / persistence context, by creating a temporary persistence context when the proxy or collection is accessed. + -Although enabling this configuration can make `LazyInitializationException` go away, it's better to use a fetch plan that guarantees that all properties are properly initialized before the Session is closed. +Enabling this setting can make `LazyInitializationException` go away, but it's much better to use a fetch plan to ensure that needed associations are fully initialized before the session is closed. + -In reality, you shouldn't probably enable this setting anyway. +IMPORTANT: This setting is not recommended, since it can easily break transaction isolation or lead to data aliasing. [[configurations-logging]] === Statement logging and statistics diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java index c79ac70884..7111ce0729 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -1971,6 +1971,12 @@ public interface AvailableSettings { String STATEMENT_INSPECTOR = "hibernate.session_factory.statement_inspector"; /** + * Allows a detached proxy or lazy collection to be fetched even when not + * associated with an open persistence context, by creating a temporary + * persistence context when the proxy or collection is accessed. This + * behavior is not recommended, since it can easily break transaction + * isolation or lead to data aliasing. It is therefore disabled by default. + * * @see org.hibernate.boot.SessionFactoryBuilder#applyLazyInitializationOutsideTransaction(boolean) */ String ENABLE_LAZY_LOAD_NO_TRANS = "hibernate.enable_lazy_load_no_trans";