Upgrade to H2 2.1.210

H2 2.x contains several important changes such as moving the primary key
generation mechanism to a sequence-based identifier. This commit fixes
a number of tests that were failing.

Closes gh-29651

Co-authored-by: Andy Wilkinson <wilkinsona@vmware.com>
This commit is contained in:
Stephane Nicoll 2022-02-04 10:14:36 +01:00
parent 5f7657508f
commit 8c8c9c5f28
11 changed files with 39 additions and 32 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 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.
@ -16,6 +16,8 @@
package org.springframework.boot.autoconfigure.flyway; package org.springframework.boot.autoconfigure.flyway;
import java.util.UUID;
import org.flywaydb.core.Flyway; import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.Location; import org.flywaydb.core.api.Location;
import org.flywaydb.core.api.MigrationVersion; import org.flywaydb.core.api.MigrationVersion;
@ -23,7 +25,7 @@ import org.flywaydb.core.api.migration.JavaMigration;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.classpath.ClassPathOverrides; import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -41,11 +43,11 @@ class Flyway5xAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(FlywayAutoConfiguration.class)) .withConfiguration(AutoConfigurations.of(FlywayAutoConfiguration.class))
.withPropertyValues("spring.datasource.generate-unique-name=true"); .withPropertyValues("spring.datasource.url:jdbc:hsqldb:mem:" + UUID.randomUUID());
@Test @Test
void defaultFlyway() { void defaultFlyway() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class).run((context) -> { this.contextRunner.withUserConfiguration(DataSourceAutoConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(Flyway.class); assertThat(context).hasSingleBean(Flyway.class);
Flyway flyway = context.getBean(Flyway.class); Flyway flyway = context.getBean(Flyway.class);
assertThat(flyway.getConfiguration().getLocations()) assertThat(flyway.getConfiguration().getLocations())
@ -56,7 +58,7 @@ class Flyway5xAutoConfigurationTests {
@Test @Test
void flywayJavaMigrationsAreIgnored() { void flywayJavaMigrationsAreIgnored() {
this.contextRunner this.contextRunner
.withUserConfiguration(EmbeddedDataSourceConfiguration.class, FlywayJavaMigrationsConfiguration.class) .withUserConfiguration(DataSourceAutoConfiguration.class, FlywayJavaMigrationsConfiguration.class)
.run((context) -> assertThat(context).hasNotFailed()); .run((context) -> assertThat(context).hasNotFailed());
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2022 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.
@ -16,6 +16,8 @@
package org.springframework.boot.autoconfigure.flyway; package org.springframework.boot.autoconfigure.flyway;
import java.util.UUID;
import org.flywaydb.core.Flyway; import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.Location; import org.flywaydb.core.api.Location;
import org.flywaydb.core.api.callback.Callback; import org.flywaydb.core.api.callback.Callback;
@ -25,7 +27,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.InOrder; import org.mockito.InOrder;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.classpath.ClassPathOverrides; import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -48,11 +50,11 @@ class Flyway6xAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(FlywayAutoConfiguration.class)) .withConfiguration(AutoConfigurations.of(FlywayAutoConfiguration.class))
.withPropertyValues("spring.datasource.generate-unique-name=true"); .withPropertyValues("spring.datasource.url:jdbc:hsqldb:mem:" + UUID.randomUUID());
@Test @Test
void defaultFlyway() { void defaultFlyway() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class).run((context) -> { this.contextRunner.withUserConfiguration(DataSourceAutoConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(Flyway.class); assertThat(context).hasSingleBean(Flyway.class);
Flyway flyway = context.getBean(Flyway.class); Flyway flyway = context.getBean(Flyway.class);
assertThat(flyway.getConfiguration().getLocations()) assertThat(flyway.getConfiguration().getLocations())
@ -62,7 +64,7 @@ class Flyway6xAutoConfigurationTests {
@Test @Test
void callbacksAreConfiguredAndOrdered() { void callbacksAreConfiguredAndOrdered() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class, CallbackConfiguration.class) this.contextRunner.withUserConfiguration(DataSourceAutoConfiguration.class, CallbackConfiguration.class)
.run((context) -> { .run((context) -> {
assertThat(context).hasSingleBean(Flyway.class); assertThat(context).hasSingleBean(Flyway.class);
Flyway flyway = context.getBean(Flyway.class); Flyway flyway = context.getBean(Flyway.class);

View File

@ -16,6 +16,8 @@
package org.springframework.boot.autoconfigure.flyway; package org.springframework.boot.autoconfigure.flyway;
import java.util.UUID;
import org.flywaydb.core.Flyway; import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.Location; import org.flywaydb.core.api.Location;
import org.flywaydb.core.api.callback.Callback; import org.flywaydb.core.api.callback.Callback;
@ -24,7 +26,7 @@ import org.flywaydb.core.api.callback.Event;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.classpath.ClassPathOverrides; import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -47,11 +49,11 @@ class Flyway7xAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(FlywayAutoConfiguration.class)) .withConfiguration(AutoConfigurations.of(FlywayAutoConfiguration.class))
.withPropertyValues("spring.datasource.generate-unique-name=true"); .withPropertyValues("spring.datasource.url:jdbc:hsqldb:mem:" + UUID.randomUUID());
@Test @Test
void defaultFlyway() { void defaultFlyway() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class).run((context) -> { this.contextRunner.withUserConfiguration(DataSourceAutoConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(Flyway.class); assertThat(context).hasSingleBean(Flyway.class);
Flyway flyway = context.getBean(Flyway.class); Flyway flyway = context.getBean(Flyway.class);
assertThat(flyway.getConfiguration().getLocations()) assertThat(flyway.getConfiguration().getLocations())
@ -61,7 +63,7 @@ class Flyway7xAutoConfigurationTests {
@Test @Test
void callbacksAreConfigured() { void callbacksAreConfigured() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class, CallbackConfiguration.class) this.contextRunner.withUserConfiguration(DataSourceAutoConfiguration.class, CallbackConfiguration.class)
.run((context) -> { .run((context) -> {
assertThat(context).hasSingleBean(Flyway.class); assertThat(context).hasSingleBean(Flyway.class);
Flyway flyway = context.getBean(Flyway.class); Flyway flyway = context.getBean(Flyway.class);

View File

@ -318,7 +318,7 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes
EntityManager em = context.getBean(EntityManagerFactory.class).createEntityManager(); EntityManager em = context.getBean(EntityManagerFactory.class).createEntityManager();
NonAnnotatedEntity found = em.find(NonAnnotatedEntity.class, 2000L); NonAnnotatedEntity found = em.find(NonAnnotatedEntity.class, 2000L);
assertThat(found).isNotNull(); assertThat(found).isNotNull();
assertThat(found.getValue()).isEqualTo("Test"); assertThat(found.getItem()).isEqualTo("Test");
}); });
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2022 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.
@ -25,13 +25,13 @@ public class NonAnnotatedEntity {
private Long id; private Long id;
private String value; private String item;
protected NonAnnotatedEntity() { protected NonAnnotatedEntity() {
} }
public NonAnnotatedEntity(String value) { public NonAnnotatedEntity(String item) {
this.value = value; this.item = item;
} }
public Long getId() { public Long getId() {
@ -42,12 +42,12 @@ public class NonAnnotatedEntity {
this.id = id; this.id = id;
} }
public String getValue() { public String getItem() {
return this.value; return this.item;
} }
public void setValue(String value) { public void setItem(String value) {
this.value = value; this.item = value;
} }
} }

View File

@ -10,8 +10,8 @@
<column name="id"/> <column name="id"/>
<generated-value strategy="IDENTITY"/> <generated-value strategy="IDENTITY"/>
</id> </id>
<basic name="value"> <basic name="item">
<column name="value"/> <column name="item"/>
</basic> </basic>
</attributes> </attributes>
</entity> </entity>

View File

@ -1 +1 @@
INSERT INTO NON_ANNOTATED (ID, VALUE) values (2000, 'Test'); INSERT INTO NON_ANNOTATED (id, item) values (2000, 'Test');

View File

@ -399,7 +399,7 @@ bom {
] ]
} }
} }
library("H2", "1.4.200") { library("H2", "2.1.210") {
group("com.h2database") { group("com.h2database") {
modules = [ modules = [
"h2" "h2"

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2022 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.
@ -27,7 +27,6 @@ import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfigurati
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.data.repository.config.BootstrapMode; import org.springframework.data.repository.config.BootstrapMode;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.TestPropertySource;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@ -41,7 +40,6 @@ import static org.springframework.boot.test.autoconfigure.AutoConfigurationImpor
* @author Scott Frederick * @author Scott Frederick
*/ */
@DataJpaTest @DataJpaTest
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
class DataJpaTestIntegrationTests { class DataJpaTestIntegrationTests {
@Autowired @Autowired
@ -71,6 +69,7 @@ class DataJpaTestIntegrationTests {
@Test @Test
void testEntityManagerPersistAndGetId() { void testEntityManagerPersistAndGetId() {
Long id = this.entities.persistAndGetId(new ExampleEntity("spring", "123"), Long.class); Long id = this.entities.persistAndGetId(new ExampleEntity("spring", "123"), Long.class);
this.entities.flush();
assertThat(id).isNotNull(); assertThat(id).isNotNull();
String reference = this.jdbcTemplate.queryForObject("SELECT REFERENCE FROM EXAMPLE_ENTITY WHERE ID = ?", String reference = this.jdbcTemplate.queryForObject("SELECT REFERENCE FROM EXAMPLE_ENTITY WHERE ID = ?",
String.class, id); String.class, id);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2022 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.
@ -20,6 +20,7 @@ import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -29,6 +30,7 @@ import org.springframework.util.Assert;
* @author Phillip Webb * @author Phillip Webb
*/ */
@Entity @Entity
@Table(name = "DRIVER")
public class User { public class User {
@Id @Id

View File

@ -1 +1 @@
INSERT INTO USER(ID, USERNAME, VIN) values (123, 'sframework', '01234567890123456'); INSERT INTO DRIVER(id, username, vin) values (123, 'sframework', '01234567890123456');