Skip to content

Commit e554549

Browse files
committed
proper logging and documentation for semi-deprecation of 'hibernate.dialect'
and code cleanup
1 parent d8c300d commit e554549

File tree

5 files changed

+276
-188
lines changed

5 files changed

+276
-188
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,11 @@ public interface AvailableSettings {
475475
* By default, Hibernate will attempt to automatically determine the dialect from the
476476
* {@linkplain #URL JDBC URL} and JDBC metadata, so this setting is not usually necessary.
477477
*
478+
* @apiNote As of Hibernate 6, this property should not be explicitly specified,
479+
* except when using a custom user-written implementation of {@code Dialect}.
480+
* Instead, applications should allow Hibernate to select the {@code Dialect}
481+
* automatically.
482+
*
478483
* @see org.hibernate.dialect.Dialect
479484
*/
480485
String DIALECT = "hibernate.dialect";

hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@
108108
* A {@linkplain Dialect SQL dialect} for DB2 for LUW (Linux, Unix, and Windows) version 10.5 and above.
109109
*
110110
* @author Gavin King
111+
*
112+
* @see DB2iDialect
113+
* @see DB2zDialect
111114
*/
112115
public class DB2Dialect extends Dialect {
113116

hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/DialectFactoryImpl.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public void setDialectResolver(DialectResolver dialectResolver) {
8484
@Override
8585
public Dialect buildDialect(Map<String,Object> configValues, DialectResolutionInfoSource resolutionInfoSource) throws HibernateException {
8686
final Object dialectReference = configValues.get( AvailableSettings.DIALECT );
87-
Dialect dialect = !isEmpty( dialectReference ) ?
88-
constructDialect( dialectReference, resolutionInfoSource ) :
89-
determineDialect( resolutionInfoSource );
87+
Dialect dialect = !isEmpty( dialectReference )
88+
? constructDialect( dialectReference, resolutionInfoSource )
89+
: determineDialect( resolutionInfoSource );
9090
logSelectedDialect( dialect );
9191
return dialect;
9292
}
@@ -105,6 +105,9 @@ private static void logSelectedDialect(Dialect dialect) {
105105
DEPRECATION_LOGGER.deprecatedDialect( dialectClass.getSimpleName() );
106106
}
107107
}
108+
else if ( Dialect.class.getPackage() == dialectClass.getPackage() ) {
109+
DEPRECATION_LOGGER.automaticDialect( dialectClass.getSimpleName() );
110+
}
108111
}
109112

110113
@SuppressWarnings("SimplifiableIfStatement")
@@ -129,7 +132,7 @@ private Dialect constructDialect(Object dialectReference, DialectResolutionInfoS
129132
(dialectClass) -> {
130133
try {
131134
try {
132-
if (resolutionInfoSource != null) {
135+
if ( resolutionInfoSource != null ) {
133136
return dialectClass.getConstructor( DialectResolutionInfo.class ).newInstance(
134137
resolutionInfoSource.getDialectResolutionInfo()
135138
);
@@ -157,7 +160,7 @@ private Dialect constructDialect(Object dialectReference, DialectResolutionInfoS
157160
final String dialectFqn = dialectReference.toString();
158161
if ( LEGACY_DIALECTS.contains( dialectFqn ) ) {
159162
throw new StrategySelectionException(
160-
"Couldn't load the dialect class for the `hibernate.dialect` [" + dialectFqn + "], " +
163+
"Couldn't load the dialect class for the 'hibernate.dialect' [" + dialectFqn + "], " +
161164
"because the application is missing a dependency on the hibernate-community-dialects module. " +
162165
"Hibernate 6.2 dropped support for database versions that are unsupported by vendors " +
163166
"and code for old versions was moved to the hibernate-community-dialects module. " +

0 commit comments

Comments
 (0)