Skip to content

Commit d94a2a7

Browse files
committed
HHH-18545 - Document "characteristics" of settings
(cherry picked from commit 4f9035e)
1 parent b5ff96d commit d94a2a7

File tree

11 files changed

+188
-83
lines changed

11 files changed

+188
-83
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: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public interface QuerySettings {
2323
* databases. By default, integer division in HQL can produce a non-integer
2424
* on Oracle, MySQL, or MariaDB.
2525
*
26+
* @settingDefault {@code false}
27+
*
2628
* @since 6.5
2729
*/
2830
String PORTABLE_INTEGER_DIVISION = "hibernate.query.hql.portable_integer_division";
@@ -53,10 +55,10 @@ public interface QuerySettings {
5355
/**
5456
* When enabled, specifies that named queries be checked during startup.
5557
* <p>
56-
* By default, named queries are checked at startup.
57-
* <p>
5858
* Mainly intended for use in test environments.
5959
*
60+
* @settingDefault {@code true} (enabled) - named queries are checked at startup.
61+
*
6062
* @see org.hibernate.boot.SessionFactoryBuilder#applyNamedQueryCheckingOnStartup(boolean)
6163
*/
6264
String QUERY_STARTUP_CHECKING = "hibernate.query.startup_check";
@@ -85,8 +87,8 @@ public interface QuerySettings {
8587
* {@link jakarta.persistence.Query#setParameter(jakarta.persistence.Parameter,Object)}
8688
* to specify its argument are passed to JDBC using a bind parameter.
8789
* </ul>
88-
* <p>
89-
* The default mode is {@link org.hibernate.query.criteria.ValueHandlingMode#BIND}.
90+
*
91+
* @settingDefault {@link org.hibernate.query.criteria.ValueHandlingMode#BIND}.
9092
*
9193
* @since 6.0.0
9294
*
@@ -101,8 +103,8 @@ public interface QuerySettings {
101103
* Specifies the default {@linkplain NullPrecedence precedence of null values} in the
102104
* HQL {@code ORDER BY} clause, either {@code none}, {@code first}, or {@code last},
103105
* or an instance of {@link NullPrecedence}.
104-
* <p>
105-
* The default is {@code none}.
106+
*
107+
* @settingDefault {@code none}.
106108
*
107109
* @see NullPrecedence
108110
* @see org.hibernate.boot.SessionFactoryBuilder#applyDefaultNullPrecedence(NullPrecedence)
@@ -135,10 +137,10 @@ public interface QuerySettings {
135137
String CRITERIA_COPY_TREE = "hibernate.criteria.copy_tree";
136138

137139
/**
138-
* When set to true, indicates that ordinal parameters (represented by the '?' placeholder) in native queries will be ignored.
139-
* <p>
140-
* By default, this is set to false, i.e. native queries will be checked for ordinal placeholders.
141-
* <p>
140+
* When enabled, ordinal parameters (represented by the {@code ?} placeholder) in
141+
* native queries will be ignored.
142+
*
143+
* @settingDefault {@code false} (disabled) - native queries are checked for ordinal placeholders.
142144
*
143145
* @see SessionFactoryOptions#getNativeJdbcParametersIgnored()
144146
*/
@@ -152,9 +154,9 @@ public interface QuerySettings {
152154
* <p>
153155
* When enabled, this setting specifies that an exception should be thrown for any
154156
* query which would result in the limit being applied in-memory.
155-
* <p>
156-
* By default, the exception is <em>disabled</em>, and the possibility of terrible
157-
* performance is left as a problem for the client to avoid.
157+
*
158+
* @settingDefault {@code false} (disabled) - no exception is thrown and the
159+
* possibility of terrible performance is left as a problem for the client to avoid.
158160
*
159161
* @since 5.2.13
160162
*/
@@ -172,8 +174,8 @@ public interface QuerySettings {
172174
* <li>{@link org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode#EXCEPTION "exception"}
173175
* specifies that a {@link org.hibernate.HibernateException} should be thrown.
174176
* </ul>
175-
* <p>
176-
* By default, a warning is logged.
177+
*
178+
* @settingDefault {@link org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode#WARNING "warning"}
177179
*
178180
* @since 5.2.17
179181
*

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

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

9+
910
import jakarta.persistence.spi.PersistenceUnitInfo;
1011

1112
/**
@@ -129,6 +130,26 @@ public interface TransactionSettings {
129130
*/
130131
String ALLOW_JTA_TRANSACTION_ACCESS = "hibernate.jta.allowTransactionAccess";
131132

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

145169
/**
@@ -153,29 +177,15 @@ public interface TransactionSettings {
153177
* <p>
154178
* The default behavior is to disallow update operations outside a transaction.
155179
*
180+
* @settingDefault {@code false} (disabled)
181+
*
182+
* @apiNote Generally speaking, all access to transactional data should be done in a transaction.
183+
* Combining this with second-level caching, e.g., will cause problems.
184+
*
156185
* @see org.hibernate.boot.SessionFactoryBuilder#allowOutOfTransactionUpdateOperations(boolean)
157186
*
158187
* @since 5.2
159188
*/
189+
@Unsafe
160190
String ALLOW_UPDATE_OUTSIDE_TRANSACTION = "hibernate.allow_update_outside_transaction";
161-
162-
/**
163-
* When enabled, specifies that the {@link org.hibernate.Session} should be
164-
* closed automatically at the end of each transaction.
165-
*
166-
* @settingDefault {@code false}
167-
*
168-
* @see org.hibernate.boot.SessionFactoryBuilder#applyAutoClosing(boolean)
169-
*/
170-
String AUTO_CLOSE_SESSION = "hibernate.transaction.auto_close_session";
171-
172-
/**
173-
* When enabled, specifies that automatic flushing should occur during the JTA
174-
* {@link jakarta.transaction.Synchronization#beforeCompletion()} callback.
175-
*
176-
* @settingDefault {@code true} unless using JPA bootstrap
177-
*
178-
* @see org.hibernate.boot.SessionFactoryBuilder#applyAutoFlushing(boolean)
179-
*/
180-
String FLUSH_BEFORE_COMPLETION = "hibernate.transaction.flush_before_completion";
181191
}
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
}

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.util.TreeMap;
1515
import java.util.TreeSet;
1616

17+
import org.jsoup.nodes.Element;
18+
1719
/**
1820
* @author Steve Ebersole
1921
*/
@@ -39,4 +41,39 @@ public static Map<SettingsDocSection, SortedSet<SettingDescriptor>> createResult
3941
} );
4042
return map;
4143
}
44+
45+
public static boolean containsHref(Element fieldJavadocElement, String target) {
46+
final String cssQuery = "a[href$=" + target + "]";
47+
final Element incubatingMarkerElement = fieldJavadocElement.selectFirst( cssQuery );
48+
return incubatingMarkerElement != null;
49+
50+
}
51+
52+
public static boolean interpretIncubation(Element fieldJavadocElement) {
53+
return containsHref( fieldJavadocElement, "Incubating.html" );
54+
}
55+
56+
public static boolean interpretUnsafe(Element fieldJavadocElement) {
57+
return containsHref( fieldJavadocElement, "Unsafe.html" );
58+
}
59+
60+
public static boolean interpretCompatibility(Element fieldJavadocElement) {
61+
return containsHref( fieldJavadocElement, "Compatibility.html" );
62+
}
63+
64+
public static boolean interpretDeprecation(Element fieldJavadocElement) {
65+
// A setting is considered deprecated with either `@Deprecated`
66+
final Element deprecationDiv = fieldJavadocElement.selectFirst( ".deprecationBlock" );
67+
// presence of this <div/> indicates the member is deprecated
68+
if ( deprecationDiv != null ) {
69+
return true;
70+
}
71+
72+
// or `@Remove`
73+
if ( containsHref( fieldJavadocElement, "Remove.html" ) ) {
74+
return true;
75+
}
76+
77+
return false;
78+
}
4279
}

0 commit comments

Comments
 (0)