Raise the minimum supported version of Hibernate to 5.2.x
Closes gh-7586
This commit is contained in:
@@ -26,7 +26,6 @@ import javax.transaction.TransactionManager;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
@@ -41,6 +40,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link HibernateJpaAutoConfiguration}.
|
||||
@@ -55,11 +55,6 @@ public class HibernateJpaAutoConfigurationTests
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
HibernateVersion.setRunning(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> getAutoConfigureClass() {
|
||||
return HibernateJpaAutoConfiguration.class;
|
||||
@@ -90,38 +85,6 @@ public class HibernateJpaAutoConfigurationTests
|
||||
.queryForObject("SELECT COUNT(*) from CITY", Integer.class)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomNamingStrategy() throws Exception {
|
||||
HibernateVersion.setRunning(HibernateVersion.V4);
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.jpa.hibernate.naming.strategy:"
|
||||
+ "org.hibernate.cfg.EJB3NamingStrategy");
|
||||
setupTestConfiguration();
|
||||
this.context.refresh();
|
||||
LocalContainerEntityManagerFactoryBean bean = this.context
|
||||
.getBean(LocalContainerEntityManagerFactoryBean.class);
|
||||
String actual = (String) bean.getJpaPropertyMap()
|
||||
.get("hibernate.ejb.naming_strategy");
|
||||
assertThat(actual).isEqualTo("org.hibernate.cfg.EJB3NamingStrategy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomNamingStrategyViaJpaProperties() throws Exception {
|
||||
HibernateVersion.setRunning(HibernateVersion.V4);
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.jpa.properties.hibernate.ejb.naming_strategy:"
|
||||
+ "org.hibernate.cfg.EJB3NamingStrategy");
|
||||
setupTestConfiguration();
|
||||
this.context.refresh();
|
||||
LocalContainerEntityManagerFactoryBean bean = this.context
|
||||
.getBean(LocalContainerEntityManagerFactoryBean.class);
|
||||
String actual = (String) bean.getJpaPropertyMap()
|
||||
.get("hibernate.ejb.naming_strategy");
|
||||
// You can't override this one from spring.jpa.properties because it has an
|
||||
// opinionated default
|
||||
assertThat(actual).isNotEqualTo("org.hibernate.cfg.EJB3NamingStrategy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlywayPlusValidation() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
@@ -175,7 +138,7 @@ public class HibernateJpaAutoConfigurationTests
|
||||
|
||||
@Override
|
||||
public TransactionManager retrieveTransactionManager() {
|
||||
throw new UnsupportedOperationException();
|
||||
return mock(TransactionManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy;
|
||||
import org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy;
|
||||
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -49,54 +48,14 @@ public class JpaPropertiesTests {
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
HibernateVersion.setRunning(null);
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hibernate4NoCustomNamingStrategy() throws Exception {
|
||||
JpaProperties properties = load(HibernateVersion.V4);
|
||||
Map<String, String> hibernateProperties = properties
|
||||
.getHibernateProperties(mockStandaloneDataSource());
|
||||
assertThat(hibernateProperties).contains(entry("hibernate.ejb.naming_strategy",
|
||||
SpringNamingStrategy.class.getName()));
|
||||
assertThat(hibernateProperties).doesNotContainKeys(
|
||||
"hibernate.implicit_naming_strategy",
|
||||
"hibernate.physical_naming_strategy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hibernate4CustomNamingStrategy() throws Exception {
|
||||
JpaProperties properties = load(HibernateVersion.V4,
|
||||
"spring.jpa.hibernate.naming.strategy:"
|
||||
+ "org.hibernate.cfg.EJB3NamingStrategy");
|
||||
Map<String, String> hibernateProperties = properties
|
||||
.getHibernateProperties(mockStandaloneDataSource());
|
||||
assertThat(hibernateProperties).contains(entry("hibernate.ejb.naming_strategy",
|
||||
"org.hibernate.cfg.EJB3NamingStrategy"));
|
||||
assertThat(hibernateProperties).doesNotContainKeys(
|
||||
"hibernate.implicit_naming_strategy",
|
||||
"hibernate.physical_naming_strategy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hibernate4CustomNamingStrategyViaJpaProperties() throws Exception {
|
||||
JpaProperties properties = load(HibernateVersion.V4,
|
||||
"spring.jpa.properties.hibernate.ejb.naming_strategy:"
|
||||
+ "org.hibernate.cfg.EJB3NamingStrategy");
|
||||
Map<String, String> hibernateProperties = properties
|
||||
.getHibernateProperties(mockStandaloneDataSource());
|
||||
String actual = hibernateProperties.get("hibernate.ejb.naming_strategy");
|
||||
// You can't override this one from spring.jpa.properties because it has an
|
||||
// opinionated default
|
||||
assertThat(actual).isNotEqualTo("org.hibernate.cfg.EJB3NamingStrategy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hibernate5NoCustomNamingStrategy() throws Exception {
|
||||
JpaProperties properties = load(HibernateVersion.V5);
|
||||
public void noCustomNamingStrategy() throws Exception {
|
||||
JpaProperties properties = load();
|
||||
Map<String, String> hibernateProperties = properties
|
||||
.getHibernateProperties(mockStandaloneDataSource());
|
||||
assertThat(hibernateProperties)
|
||||
@@ -111,7 +70,7 @@ public class JpaPropertiesTests {
|
||||
|
||||
@Test
|
||||
public void hibernate5CustomNamingStrategies() throws Exception {
|
||||
JpaProperties properties = load(HibernateVersion.V5,
|
||||
JpaProperties properties = load(
|
||||
"spring.jpa.hibernate.naming.implicit-strategy:com.example.Implicit",
|
||||
"spring.jpa.hibernate.naming.physical-strategy:com.example.Physical");
|
||||
Map<String, String> hibernateProperties = properties
|
||||
@@ -125,7 +84,7 @@ public class JpaPropertiesTests {
|
||||
|
||||
@Test
|
||||
public void hibernate5CustomNamingStrategiesViaJpaProperties() throws Exception {
|
||||
JpaProperties properties = load(HibernateVersion.V5,
|
||||
JpaProperties properties = load(
|
||||
"spring.jpa.properties.hibernate.implicit_naming_strategy:com.example.Implicit",
|
||||
"spring.jpa.properties.hibernate.physical_naming_strategy:com.example.Physical");
|
||||
Map<String, String> hibernateProperties = properties
|
||||
@@ -139,17 +98,8 @@ public class JpaPropertiesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useNewIdGeneratorMappingsDefaultHibernate4() throws Exception {
|
||||
JpaProperties properties = load(HibernateVersion.V4);
|
||||
Map<String, String> hibernateProperties = properties
|
||||
.getHibernateProperties(mockStandaloneDataSource());
|
||||
assertThat(hibernateProperties)
|
||||
.doesNotContainKey(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useNewIdGeneratorMappingsDefaultHibernate5() throws Exception {
|
||||
JpaProperties properties = load(HibernateVersion.V5);
|
||||
public void useNewIdGeneratorMappingsDefault() throws Exception {
|
||||
JpaProperties properties = load();
|
||||
Map<String, String> hibernateProperties = properties
|
||||
.getHibernateProperties(mockStandaloneDataSource());
|
||||
assertThat(hibernateProperties)
|
||||
@@ -158,7 +108,7 @@ public class JpaPropertiesTests {
|
||||
|
||||
@Test
|
||||
public void useNewIdGeneratorMappingsTrue() throws Exception {
|
||||
JpaProperties properties = load(HibernateVersion.V5,
|
||||
JpaProperties properties = load(
|
||||
"spring.jpa.hibernate.use-new-id-generator-mappings:true");
|
||||
Map<String, String> hibernateProperties = properties
|
||||
.getHibernateProperties(mockStandaloneDataSource());
|
||||
@@ -173,8 +123,7 @@ public class JpaPropertiesTests {
|
||||
return ds;
|
||||
}
|
||||
|
||||
private JpaProperties load(HibernateVersion hibernateVersion, String... environment) {
|
||||
HibernateVersion.setRunning(hibernateVersion);
|
||||
private JpaProperties load(String... environment) {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(ctx, environment);
|
||||
ctx.register(TestConfiguration.class);
|
||||
|
||||
@@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(ModifiedClassPathRunner.class)
|
||||
@ClassPathExclusions("tomcat-embed-el-*.jar")
|
||||
@ClassPathExclusions({ "tomcat-embed-el-*.jar", "el-api-*.jar" })
|
||||
public class ValidationAutoConfigurationWithHibernateValidatorMissingElImplTests {
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@@ -3,6 +3,8 @@ databaseChangeLog:
|
||||
id: 1
|
||||
author: dsyer
|
||||
changes:
|
||||
- createSequence:
|
||||
sequenceName: hibernate_sequence
|
||||
- createTable:
|
||||
tableName: city
|
||||
columns:
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
CREATE SEQUENCE HIBERNATE_SEQUENCE;
|
||||
|
||||
CREATE TABLE CITY (
|
||||
id BIGINT GENERATED BY DEFAULT AS IDENTITY,
|
||||
name VARCHAR(30),
|
||||
state VARCHAR(30),
|
||||
country VARCHAR(30),
|
||||
map VARCHAR(30)
|
||||
);
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user