Affects: Spring Boot 3.1.2


Hello,

base data: Using JDK 17, I'm trying to update from Spring Boot 2.7.12 -> 3.1.2. We're using a Postgres (version: 42.6.0) in production, that's why we're using h2 (version 2.1.214) with MODE=PostgreSQL, but no explicit dialect setting.

The application consists of multiple modules, one which provides access to the persistence layer. It defines multiple entities, for which the database is setup using Liquibase (version: 4.23.0). The tests override this setting, having Liquibase setup the DB, before Hibernate drops the tables and re-creates them (create-drop).

One of our integration test looks as follows:

package my.service;

import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@ExtendWith(SpringExtension.class)
@SpringBootTest
@ActiveProfiles("test")
class MyInternalServiceTest {

    @Autowired
    private MyInternalService myInternalService;

    @Test
    public void aVeryWellDesignedTest() {
        /* something */
    }

    @ComponentScan(basePackages = "my")
    @EnableJpaRepositories(basePackages = "my.persistence")
    @EntityScan(basePackages = "my.persistence")
    @SpringBootApplication
    @Profile("test")
    @PropertySource("classpath:application-test.yml")
    static class TestConfiguration {}
}

application-test.yml:

spring:
  datasource:
    driver-class-name: org.h2.Driver
    username: sa
    password:
    url: jdbc:h2:mem:tests;DB_CLOSE_DELAY=-1;MODE=PostgreSQL;DB_CLOSE_ON_EXIT=FALSE

  jpa:
    hibernate:
      ddl-auto: create-drop
  main:
    allow-bean-definition-overriding: true

With Spring The test boots up, the DB gets created using Liquibase, re-created using Hibernate and the test then does its job - all good.

If I now change to Spring Boot 3.1.2, Hibernate somehow cannot properly detect the target DB. It seems to use statements, that are not suitable to our H2/Postgres environment. E.g., it tries to create columns using type TINYINT for enumeration attributes or BIGINT for Long. It also cannot delete tables, that are referenced by foreign keys (it cannot remove those FKs) and sequences are also not created - or cannot be used, because it uses the wrong statement to obtain the next value. For the table creation statement, I get for example:

UPDATE SUMMARY
Run:                         73
Previously run:               0
Filtered out:                 0
-------------------------------
Total change sets:           73

Liquibase: Die Update-Operation war erfolgreich.
2023-08-13T09:21:50.571+02:00  WARN 10865 --- [           main] o.h.t.s.i.ExceptionHandlerLoggedImpl     : GenerationTarget encountered exception accepting command : Error executing DDL "create table inouthistory (active boolean, geoeventsource integer, geofencestatus tinyint check (geofencestatus between 0 and 5), geotimestamp timestamp(6), id bigint not null, lastupdatetime timestamp(6), vehicleid bigint, primary key (id))" via JDBC [Unbekannter Datentyp: "TINYINT"
Unknown data type: "TINYINT";]

Note: "Liquibase: Die Update-Operation war erfolgreich." means something like "Liquibase: The Update-Operation finished successfully."

This gets resolved though, when I change @SpringBootTest to @org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest: the tables can be dropped and re-created by Hibernate (the test fails during the application context setup though).

To me, this seems to be a bug, since @DataJpaTest is supposed to be used for repository tests only - not for ITs. This may also be the reason, why I'm having trouble booting the application context.

I wonder, if this issue here is the cause for #31044.

Please do not hesitate to ask for anything, if it might help you understand/resolve the issue.

Thanks. Stefan

PS: sorry for the weird code style, but this ticket system seems not to pick up code properly, although marked using the code tag provided...

Comment From: sbrannen

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

I also recommend that you read the documentation for Spring Boot's testing support -- for example, you might find @TestConfiguration useful.

Comment From: sbrannen

PS: sorry for the weird code style, but this ticket system seems not to pick up code properly, although marked using the code tag provided...

Don't worry about it. I revised the formatting for you (here as well as in #31044).

You might want to check out this Mastering Markdown guide for future reference.

Keep in mind that a single back ticks are for inlined code style; whereas, triple back ticks are for code blocks.

Comment From: stefan-schilling

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

I also recommend that you read the documentation for Spring Boot's testing support -- for example, you might find @TestConfiguration useful.

Hello @sbrannen , thanks for your comment. I think this is a bug, because code was not changed but fails after the Spring Boot update - and I wouldn't know, what is wrong about it. But since there was a major overhaul in the background (Spring Boot 2.7 -> 3.1) and suddenly it fails, it kind of points to that being an issue with Spring, not the code or config.

But I will post it at SO - maybe I did miss something here.

Regards, Stefan

Comment From: stefan-schilling

PS: sorry for the weird code style, but this ticket system seems not to pick up code properly, although marked using the code tag provided...

Don't worry about it. I revised the formatting for you (here as well as in #31044).

You might want to check out this Mastering Markdown guide for future reference.

Keep in mind that a single back ticks are for inlined code style; whereas, triple back ticks are for code blocks.

Hello @sbrannen ,

oh, I really didn't know that. I just used the graphical editor's "code" thing and this just adds the single ticks. And there is no indication for the 3 ticks one.... thanks :) Stefan