|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2022 the original author or authors. |
|
|
|
* Copyright 2002-2023 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -28,6 +28,7 @@ import org.hibernate.Session; |
|
|
|
import org.hibernate.SessionFactory; |
|
|
|
import org.hibernate.SessionFactory; |
|
|
|
import org.hibernate.cfg.AvailableSettings; |
|
|
|
import org.hibernate.cfg.AvailableSettings; |
|
|
|
import org.hibernate.dialect.DB2Dialect; |
|
|
|
import org.hibernate.dialect.DB2Dialect; |
|
|
|
|
|
|
|
import org.hibernate.dialect.DerbyDialect; |
|
|
|
import org.hibernate.dialect.DerbyTenSevenDialect; |
|
|
|
import org.hibernate.dialect.DerbyTenSevenDialect; |
|
|
|
import org.hibernate.dialect.H2Dialect; |
|
|
|
import org.hibernate.dialect.H2Dialect; |
|
|
|
import org.hibernate.dialect.HANAColumnStoreDialect; |
|
|
|
import org.hibernate.dialect.HANAColumnStoreDialect; |
|
|
|
@ -36,15 +37,17 @@ import org.hibernate.dialect.Informix10Dialect; |
|
|
|
import org.hibernate.dialect.MySQL57Dialect; |
|
|
|
import org.hibernate.dialect.MySQL57Dialect; |
|
|
|
import org.hibernate.dialect.Oracle12cDialect; |
|
|
|
import org.hibernate.dialect.Oracle12cDialect; |
|
|
|
import org.hibernate.dialect.PostgreSQL95Dialect; |
|
|
|
import org.hibernate.dialect.PostgreSQL95Dialect; |
|
|
|
|
|
|
|
import org.hibernate.dialect.PostgreSQLDialect; |
|
|
|
import org.hibernate.dialect.SQLServer2012Dialect; |
|
|
|
import org.hibernate.dialect.SQLServer2012Dialect; |
|
|
|
import org.hibernate.dialect.SybaseDialect; |
|
|
|
import org.hibernate.dialect.SybaseDialect; |
|
|
|
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; |
|
|
|
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
|
|
|
|
import org.springframework.util.ClassUtils; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Hibernate. |
|
|
|
* {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Hibernate. |
|
|
|
* Compatible with Hibernate ORM 5.5/5.6 as well as 6.0/6.1. |
|
|
|
* Compatible with Hibernate ORM 5.5/5.6 as well as 6.0/6.1/6.2. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>Exposes Hibernate's persistence provider and Hibernate's Session as extended |
|
|
|
* <p>Exposes Hibernate's persistence provider and Hibernate's Session as extended |
|
|
|
* EntityManager interface, and adapts {@link AbstractJpaVendorAdapter}'s common |
|
|
|
* EntityManager interface, and adapts {@link AbstractJpaVendorAdapter}'s common |
|
|
|
@ -69,6 +72,9 @@ import org.springframework.lang.Nullable; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter { |
|
|
|
public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final boolean oldDialectsPresent = ClassUtils.isPresent( |
|
|
|
|
|
|
|
"org.hibernate.dialect.PostgreSQL95Dialect", HibernateJpaVendorAdapter.class.getClassLoader()); |
|
|
|
|
|
|
|
|
|
|
|
private final HibernateJpaDialect jpaDialect = new HibernateJpaDialect(); |
|
|
|
private final HibernateJpaDialect jpaDialect = new HibernateJpaDialect(); |
|
|
|
|
|
|
|
|
|
|
|
private final PersistenceProvider persistenceProvider; |
|
|
|
private final PersistenceProvider persistenceProvider; |
|
|
|
@ -167,22 +173,40 @@ public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter { |
|
|
|
* @param database the target database |
|
|
|
* @param database the target database |
|
|
|
* @return the Hibernate database dialect class, or {@code null} if none found |
|
|
|
* @return the Hibernate database dialect class, or {@code null} if none found |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@SuppressWarnings("deprecation") // for Derby/PostgreSQLDialect on Hibernate 6.2
|
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
protected Class<?> determineDatabaseDialectClass(Database database) { |
|
|
|
protected Class<?> determineDatabaseDialectClass(Database database) { |
|
|
|
return switch (database) { |
|
|
|
if (oldDialectsPresent) { // Hibernate <6.2
|
|
|
|
case DB2 -> DB2Dialect.class; |
|
|
|
return switch (database) { |
|
|
|
case DERBY -> DerbyTenSevenDialect.class; |
|
|
|
case DB2 -> DB2Dialect.class; |
|
|
|
case H2 -> H2Dialect.class; |
|
|
|
case DERBY -> DerbyTenSevenDialect.class; |
|
|
|
case HANA -> HANAColumnStoreDialect.class; |
|
|
|
case H2 -> H2Dialect.class; |
|
|
|
case HSQL -> HSQLDialect.class; |
|
|
|
case HANA -> HANAColumnStoreDialect.class; |
|
|
|
case INFORMIX -> Informix10Dialect.class; |
|
|
|
case HSQL -> HSQLDialect.class; |
|
|
|
case MYSQL -> MySQL57Dialect.class; |
|
|
|
case INFORMIX -> Informix10Dialect.class; |
|
|
|
case ORACLE -> Oracle12cDialect.class; |
|
|
|
case MYSQL -> MySQL57Dialect.class; |
|
|
|
case POSTGRESQL -> PostgreSQL95Dialect.class; |
|
|
|
case ORACLE -> Oracle12cDialect.class; |
|
|
|
case SQL_SERVER -> SQLServer2012Dialect.class; |
|
|
|
case POSTGRESQL -> PostgreSQL95Dialect.class; |
|
|
|
case SYBASE -> SybaseDialect.class; |
|
|
|
case SQL_SERVER -> SQLServer2012Dialect.class; |
|
|
|
default -> null; |
|
|
|
case SYBASE -> SybaseDialect.class; |
|
|
|
}; |
|
|
|
default -> null; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { // Hibernate 6.2 aligned
|
|
|
|
|
|
|
|
return switch (database) { |
|
|
|
|
|
|
|
case DB2 -> DB2Dialect.class; |
|
|
|
|
|
|
|
case DERBY -> DerbyDialect.class; |
|
|
|
|
|
|
|
case H2 -> H2Dialect.class; |
|
|
|
|
|
|
|
case HANA -> HANAColumnStoreDialect.class; |
|
|
|
|
|
|
|
case HSQL -> HSQLDialect.class; |
|
|
|
|
|
|
|
case MYSQL -> MySQL57Dialect.class; |
|
|
|
|
|
|
|
case ORACLE -> Oracle12cDialect.class; |
|
|
|
|
|
|
|
case POSTGRESQL -> PostgreSQLDialect.class; |
|
|
|
|
|
|
|
case SQL_SERVER -> SQLServer2012Dialect.class; |
|
|
|
|
|
|
|
case SYBASE -> SybaseDialect.class; |
|
|
|
|
|
|
|
default -> null; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|