22
22
import javax .persistence .EntityManagerFactory ;
23
23
import javax .persistence .spi .PersistenceProvider ;
24
24
25
+ import org .hibernate .cfg .AvailableSettings ;
25
26
import org .hibernate .cfg .Environment ;
26
27
import org .hibernate .dialect .DB2Dialect ;
28
+ import org .hibernate .dialect .DerbyTenSevenDialect ;
27
29
import org .hibernate .dialect .H2Dialect ;
28
30
import org .hibernate .dialect .HSQLDialect ;
29
31
import org .hibernate .dialect .InformixDialect ;
30
- import org .hibernate .dialect .MySQLDialect ;
31
- import org .hibernate .dialect .Oracle9iDialect ;
32
- import org .hibernate .dialect .SQLServerDialect ;
32
+ import org .hibernate .dialect .MySQL5Dialect ;
33
+ import org .hibernate .dialect .Oracle12cDialect ;
34
+ import org .hibernate .dialect .PostgreSQL95Dialect ;
35
+ import org .hibernate .dialect .SQLServer2012Dialect ;
36
+ import org .hibernate .dialect .SybaseDialect ;
33
37
34
38
/**
35
39
* {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Hibernate
36
40
* EntityManager. Developed and tested against Hibernate 5.0, 5.1 and 5.2;
37
- * backwards-compatible with Hibernate 4.3 as well .
41
+ * backwards-compatible with Hibernate 4.3 at runtime on a best-effort basis .
38
42
*
39
43
* <p>Exposes Hibernate's persistence provider and EntityManager extension interface,
40
44
* and adapts {@link AbstractJpaVendorAdapter}'s common configuration settings.
@@ -121,8 +125,22 @@ else if (getDatabase() != null) {
121
125
}
122
126
123
127
if (this .jpaDialect .prepareConnection ) {
124
- // Hibernate 5.2: manually enforce connection release mode ON_CLOSE (the former default)
125
- jpaProperties .put ("hibernate.connection.handling_mode" , "DELAYED_ACQUISITION_AND_HOLD" );
128
+ // Hibernate 5.1/5.2: manually enforce connection release mode ON_CLOSE (the former default)
129
+ try {
130
+ // Try Hibernate 5.2
131
+ AvailableSettings .class .getField ("CONNECTION_HANDLING" );
132
+ jpaProperties .put ("hibernate.connection.handling_mode" , "DELAYED_ACQUISITION_AND_HOLD" );
133
+ }
134
+ catch (NoSuchFieldException ex ) {
135
+ // Try Hibernate 5.1
136
+ try {
137
+ AvailableSettings .class .getField ("ACQUIRE_CONNECTIONS" );
138
+ jpaProperties .put ("hibernate.connection.release_mode" , "ON_CLOSE" );
139
+ }
140
+ catch (NoSuchFieldException ex2 ) {
141
+ // on Hibernate 5.0.x or lower - no need to change the default there
142
+ }
143
+ }
126
144
}
127
145
128
146
return jpaProperties ;
@@ -133,19 +151,18 @@ else if (getDatabase() != null) {
133
151
* @param database the target database
134
152
* @return the Hibernate database dialect class, or {@code null} if none found
135
153
*/
136
- @ SuppressWarnings ("deprecation" )
137
154
protected Class <?> determineDatabaseDialectClass (Database database ) {
138
155
switch (database ) {
139
156
case DB2 : return DB2Dialect .class ;
140
- case DERBY : return org . hibernate . dialect . DerbyDialect .class ;
157
+ case DERBY : return DerbyTenSevenDialect .class ;
141
158
case H2 : return H2Dialect .class ;
142
159
case HSQL : return HSQLDialect .class ;
143
160
case INFORMIX : return InformixDialect .class ;
144
- case MYSQL : return MySQLDialect .class ;
145
- case ORACLE : return Oracle9iDialect .class ;
146
- case POSTGRESQL : return org . hibernate . dialect . PostgreSQLDialect .class ;
147
- case SQL_SERVER : return SQLServerDialect .class ;
148
- case SYBASE : return org . hibernate . dialect . SybaseDialect .class ;
161
+ case MYSQL : return MySQL5Dialect .class ;
162
+ case ORACLE : return Oracle12cDialect .class ;
163
+ case POSTGRESQL : return PostgreSQL95Dialect .class ;
164
+ case SQL_SERVER : return SQLServer2012Dialect .class ;
165
+ case SYBASE : return SybaseDialect .class ;
149
166
default : return null ;
150
167
}
151
168
}
0 commit comments