Skip to content

Commit 4f9035e

Browse files
committed
HHH-18545 - Document "characteristics" of settings
1 parent d4ef44d commit 4f9035e

File tree

11 files changed

+195
-86
lines changed

11 files changed

+195
-86
lines changed

documentation/documentation.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ settingsDocumentation {
573573
}
574574
transaction {
575575
explicitPosition = 6
576-
summary = "Proxool Connection Pool Settings"
576+
summary = "Transaction Environment Settings"
577577
description = "Settings which control how Hibernate interacts with and manages transactions"
578578
settingsClassName "org.hibernate.cfg.TransactionSettings"
579579
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.cfg;
6+
7+
import java.lang.annotation.Documented;
8+
import java.lang.annotation.ElementType;
9+
import java.lang.annotation.RetentionPolicy;
10+
import java.lang.annotation.Target;
11+
import java.lang.annotation.Retention;
12+
13+
/**
14+
* Denotes that a setting is intended to allow applications to upgrade
15+
* versions of Hibernate and maintain backwards compatibility with the
16+
* older version in some specific behavior. Such settings are almost always
17+
* considered temporary and are usually also {@linkplain Deprecated deprecated}.
18+
*/
19+
@Target(ElementType.FIELD)
20+
@Retention(RetentionPolicy.RUNTIME)
21+
@Documented
22+
public @interface Compatibility {
23+
}

hibernate-core/src/main/java/org/hibernate/cfg/QuerySettings.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
public interface QuerySettings {
1919
/**
2020
* Boolean setting to control if the use of tech preview JSON functions in HQL is enabled.
21-
* By default, this is {@code false} i.e. disabled since the functions are still incubating.
21+
*
22+
* @settingDefault {@code false} (disabled) since the functions are still incubating.
2223
*
2324
* @since 7.0
2425
*/
@@ -27,7 +28,8 @@ public interface QuerySettings {
2728

2829
/**
2930
* Boolean setting to control if the use of tech preview XML functions in HQL is enabled.
30-
* By default, this is {@code false} i.e. disabled since the functions are still incubating.
31+
*
32+
* @settingDefault {@code false} (disabled) since the functions are still incubating.
3133
*
3234
* @since 7.0
3335
*/
@@ -39,6 +41,8 @@ public interface QuerySettings {
3941
* databases. By default, integer division in HQL can produce a non-integer
4042
* on Oracle, MySQL, or MariaDB.
4143
*
44+
* @settingDefault {@code false}
45+
*
4246
* @since 6.5
4347
*/
4448
String PORTABLE_INTEGER_DIVISION = "hibernate.query.hql.portable_integer_division";
@@ -70,10 +74,10 @@ public interface QuerySettings {
7074
/**
7175
* When enabled, specifies that named queries be checked during startup.
7276
* <p>
73-
* By default, named queries are checked at startup.
74-
* <p>
7577
* Mainly intended for use in test environments.
7678
*
79+
* @settingDefault {@code true} (enabled) - named queries are checked at startup.
80+
*
7781
* @see org.hibernate.boot.SessionFactoryBuilder#applyNamedQueryCheckingOnStartup(boolean)
7882
*/
7983
String QUERY_STARTUP_CHECKING = "hibernate.query.startup_check";
@@ -102,8 +106,8 @@ public interface QuerySettings {
102106
* {@link jakarta.persistence.Query#setParameter(jakarta.persistence.Parameter,Object)}
103107
* to specify its argument are passed to JDBC using a bind parameter.
104108
* </ul>
105-
* <p>
106-
* The default mode is {@link org.hibernate.query.criteria.ValueHandlingMode#BIND}.
109+
*
110+
* @settingDefault {@link org.hibernate.query.criteria.ValueHandlingMode#BIND}.
107111
*
108112
* @since 6.0.0
109113
*
@@ -119,8 +123,8 @@ public interface QuerySettings {
119123
* of null values} sorted via the HQL {@code ORDER BY} clause, either {@code none},
120124
* {@code first}, or {@code last}, or an instance of the enumeration
121125
* {@link jakarta.persistence.criteria.Nulls}.
122-
* <p>
123-
* The default is {@code none}.
126+
*
127+
* @settingDefault {@code none}.
124128
*
125129
* @see jakarta.persistence.criteria.Nulls
126130
* @see org.hibernate.boot.SessionFactoryBuilder#applyDefaultNullPrecedence(jakarta.persistence.criteria.Nulls)
@@ -155,8 +159,8 @@ public interface QuerySettings {
155159
/**
156160
* When enabled, ordinal parameters (represented by the {@code ?} placeholder) in
157161
* native queries will be ignored.
158-
* <p>
159-
* By default, native queries are checked for ordinal placeholders.
162+
*
163+
* @settingDefault {@code false} (disabled) - native queries are checked for ordinal placeholders.
160164
*
161165
* @see SessionFactoryOptions#getNativeJdbcParametersIgnored()
162166
*/
@@ -167,12 +171,14 @@ public interface QuerySettings {
167171
* {@link java.sql.Time}, and {@link java.sql.Timestamp} instead of the
168172
* datetime types from {@link java.time}, recovering the behavior of
169173
* native queries in Hibernate 6 and earlier.
170-
* <p>
171-
* By default, native queries return {@link java.time.LocalDate},
172-
* {@link java.time.LocalTime}, and {@link java.time.LocalDateTime}.
174+
*
175+
* @settingDefault {@code false} (disabled) - native queries return
176+
* {@link java.time.LocalDate}, {@link java.time.LocalTime}, and
177+
* {@link java.time.LocalDateTime}.
173178
*
174179
* @since 7.0
175180
*/
181+
@Compatibility
176182
String NATIVE_PREFER_JDBC_DATETIME_TYPES = "hibernate.query.native.prefer_jdbc_datetime_types";
177183

178184
/**
@@ -183,9 +189,9 @@ public interface QuerySettings {
183189
* <p>
184190
* When enabled, this setting specifies that an exception should be thrown for any
185191
* query which would result in the limit being applied in-memory.
186-
* <p>
187-
* By default, the exception is <em>disabled</em>, and the possibility of terrible
188-
* performance is left as a problem for the client to avoid.
192+
*
193+
* @settingDefault {@code false} (disabled) - no exception is thrown and the
194+
* possibility of terrible performance is left as a problem for the client to avoid.
189195
*
190196
* @since 5.2.13
191197
*/
@@ -203,8 +209,8 @@ public interface QuerySettings {
203209
* <li>{@link org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode#EXCEPTION "exception"}
204210
* specifies that a {@link org.hibernate.HibernateException} should be thrown.
205211
* </ul>
206-
* <p>
207-
* By default, a warning is logged.
212+
*
213+
* @settingDefault {@link org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode#WARNING "warning"}
208214
*
209215
* @since 5.2.17
210216
*

hibernate-core/src/main/java/org/hibernate/cfg/TransactionSettings.java

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
package org.hibernate.cfg;
66

7+
78
import jakarta.persistence.spi.PersistenceUnitInfo;
89

910
/**
@@ -127,6 +128,26 @@ public interface TransactionSettings {
127128
*/
128129
String ALLOW_JTA_TRANSACTION_ACCESS = "hibernate.jta.allowTransactionAccess";
129130

131+
/**
132+
* When enabled, specifies that the {@link org.hibernate.Session} should be
133+
* closed automatically at the end of each transaction.
134+
*
135+
* @settingDefault {@code false}
136+
*
137+
* @see org.hibernate.boot.SessionFactoryBuilder#applyAutoClosing(boolean)
138+
*/
139+
String AUTO_CLOSE_SESSION = "hibernate.transaction.auto_close_session";
140+
141+
/**
142+
* When enabled, specifies that automatic flushing should occur during the JTA
143+
* {@link jakarta.transaction.Synchronization#beforeCompletion()} callback.
144+
*
145+
* @settingDefault {@code true} unless using JPA bootstrap
146+
*
147+
* @see org.hibernate.boot.SessionFactoryBuilder#applyAutoFlushing(boolean)
148+
*/
149+
String FLUSH_BEFORE_COMPLETION = "hibernate.transaction.flush_before_completion";
150+
130151
/**
131152
* Allows a detached proxy or lazy collection to be fetched even when not
132153
* associated with an open persistence context, by creating a temporary
@@ -136,8 +157,11 @@ public interface TransactionSettings {
136157
*
137158
* @settingDefault {@code false} (disabled)
138159
*
160+
* @apiNote Generally speaking, all access to transactional data should be done in a transaction.
161+
*
139162
* @see org.hibernate.boot.SessionFactoryBuilder#applyLazyInitializationOutsideTransaction(boolean)
140163
*/
164+
@Unsafe
141165
String ENABLE_LAZY_LOAD_NO_TRANS = "hibernate.enable_lazy_load_no_trans";
142166

143167
/**
@@ -151,29 +175,15 @@ public interface TransactionSettings {
151175
* <p>
152176
* The default behavior is to disallow update operations outside a transaction.
153177
*
178+
* @settingDefault {@code false} (disabled)
179+
*
180+
* @apiNote Generally speaking, all access to transactional data should be done in a transaction.
181+
* Combining this with second-level caching, e.g., will cause problems.
182+
*
154183
* @see org.hibernate.boot.SessionFactoryBuilder#allowOutOfTransactionUpdateOperations(boolean)
155184
*
156185
* @since 5.2
157186
*/
187+
@Unsafe
158188
String ALLOW_UPDATE_OUTSIDE_TRANSACTION = "hibernate.allow_update_outside_transaction";
159-
160-
/**
161-
* When enabled, specifies that the {@link org.hibernate.Session} should be
162-
* closed automatically at the end of each transaction.
163-
*
164-
* @settingDefault {@code false}
165-
*
166-
* @see org.hibernate.boot.SessionFactoryBuilder#applyAutoClosing(boolean)
167-
*/
168-
String AUTO_CLOSE_SESSION = "hibernate.transaction.auto_close_session";
169-
170-
/**
171-
* When enabled, specifies that automatic flushing should occur during the JTA
172-
* {@link jakarta.transaction.Synchronization#beforeCompletion()} callback.
173-
*
174-
* @settingDefault {@code true} unless using JPA bootstrap
175-
*
176-
* @see org.hibernate.boot.SessionFactoryBuilder#applyAutoFlushing(boolean)
177-
*/
178-
String FLUSH_BEFORE_COMPLETION = "hibernate.transaction.flush_before_completion";
179189
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.cfg;
6+
7+
import java.lang.annotation.Documented;
8+
import java.lang.annotation.ElementType;
9+
import java.lang.annotation.RetentionPolicy;
10+
import java.lang.annotation.Target;
11+
import java.lang.annotation.Retention;
12+
13+
/**
14+
* Denotes that a setting is considered unsafe. Generally these are settings
15+
* added for temporary use during porting of applications. Unsafe settings
16+
* are largely considered unsupported.
17+
*/
18+
@Target(ElementType.FIELD)
19+
@Retention(RetentionPolicy.RUNTIME)
20+
@Documented
21+
public @interface Unsafe {
22+
}

local-build-plugins/src/main/java/org/hibernate/orm/properties/AsciiDocWriter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ private static void writeMetadata(SettingDescriptor settingDescriptor, FileWrite
109109
if ( lifecycleDetails.isDeprecated() ) {
110110
writer.write( "WARNING: *_This setting is considered deprecated_*\n\n" );
111111
}
112+
if ( settingDescriptor.isUnsafe() ) {
113+
writer.write( "WARNING: *_This setting is considered unsafe_*\n\n" );
114+
}
115+
if ( settingDescriptor.isCompatibility() ) {
116+
writer.write( "INFO: *_This setting manages a certain backwards compatibility_*\n\n" );
117+
}
112118

113119
if ( lifecycleDetails.getSince() != null ) {
114120
writer.write( "*_Since:_* _" + lifecycleDetails.getSince() + "_\n\n" );

local-build-plugins/src/main/java/org/hibernate/orm/properties/SettingDescriptor.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class SettingDescriptor {
1818
private final String defaultValue;
1919
private final String apiNote;
2020
private final LifecycleDetails lifecycleDetails;
21+
private final boolean unsafe;
22+
private final boolean compatibility;
2123

2224
public SettingDescriptor(
2325
String name,
@@ -27,6 +29,8 @@ public SettingDescriptor(
2729
String comment,
2830
String defaultValue,
2931
String apiNote,
32+
boolean unsafe,
33+
boolean compatibility,
3034
LifecycleDetails lifecycleDetails) {
3135
this.name = name;
3236
this.settingsClassName = settingsClassName;
@@ -35,6 +39,8 @@ public SettingDescriptor(
3539
this.publishedJavadocLink = publishedJavadocLink;
3640
this.defaultValue = defaultValue;
3741
this.apiNote = apiNote;
42+
this.unsafe = unsafe;
43+
this.compatibility = compatibility;
3844
this.lifecycleDetails = lifecycleDetails;
3945
}
4046

@@ -48,14 +54,18 @@ public SettingDescriptor(
4854
String apiNote,
4955
String since,
5056
boolean deprecated,
51-
boolean incubating) {
57+
boolean incubating,
58+
boolean unsafe,
59+
boolean compatibility) {
5260
this(
5361
name,
5462
settingsClassName,
5563
settingFieldName,
5664
publishedJavadocLink, comment,
5765
defaultValue,
5866
apiNote,
67+
unsafe,
68+
compatibility,
5969
new LifecycleDetails( since, deprecated, incubating )
6070
);
6171
}
@@ -100,6 +110,14 @@ public String getSettingFieldName() {
100110
return settingFieldName;
101111
}
102112

113+
public boolean isUnsafe() {
114+
return unsafe;
115+
}
116+
117+
public boolean isCompatibility() {
118+
return compatibility;
119+
}
120+
103121
public LifecycleDetails getLifecycleDetails() {
104122
return lifecycleDetails;
105123
}

local-build-plugins/src/main/java/org/hibernate/orm/properties/SettingWorkingDetails.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class SettingWorkingDetails {
2323
private String since;
2424
private boolean deprecated;
2525
private boolean incubating;
26+
private boolean unsafe;
27+
private boolean compatibility;
2628
private List<String> relatedSettingNames;
2729

2830
public SettingWorkingDetails(
@@ -92,6 +94,22 @@ public void setIncubating(boolean incubating) {
9294
this.incubating = incubating;
9395
}
9496

97+
public boolean isUnsafe() {
98+
return unsafe;
99+
}
100+
101+
public void setUnsafe(boolean unsafe) {
102+
this.unsafe = unsafe;
103+
}
104+
105+
public boolean isCompatibility() {
106+
return compatibility;
107+
}
108+
109+
public void setCompatibility(boolean compatibility) {
110+
this.compatibility = compatibility;
111+
}
112+
95113
public List<String> getRelatedSettingNames() {
96114
return relatedSettingNames;
97115
}
@@ -134,7 +152,9 @@ public SettingDescriptor buildDescriptor(String asciidoc) {
134152
apiNote,
135153
since,
136154
deprecated,
137-
incubating
155+
incubating,
156+
unsafe,
157+
compatibility
138158
);
139159
}
140160
}

0 commit comments

Comments
 (0)