Search code examples
sqlspring-bootspring-boot-testspring-boot-3

Springboot integration test fails after upgrading from springboot 3.1.5 to 3.2.0


Everything works fine in Springboot 3.1.5 but...when I updrade to Springboot 3.2.0, I encounter error such as Fail to load application context

Database: MySQL

Unit test database: H2

I check the log and found that it was caused by this error:

org.hibernate.tool.schema.spi.CommandAcceptanceException: 
Error executing DDL 
"create table guest_boot_notification (id varchar(255) generated by default 
as identity, link_id varchar(255), 
notification_lang varchar(255) check (notification_lang in ('EN','GE','ZH','ZH_TW')), type varchar(255) check (type in ('CHAIR','CABINET','TABLE','SOFA')), 
web_hook_url varchar(255), primary key (id))" 
via JDBC [Feature not supported: "CHARACTER VARYING(255)";]

Another error is

Caused by: java.lang.IllegalArgumentException: 
org.hibernate.query.SemanticException: 
Operand of + is of type 'java.lang.Object' 
which is not a numeric type (it is not an instance of 
'java.lang.Number', 'java.time.Temporal', or 'java.time.TemporalAmount')

Anybody encounter such issue? Any help is appreciated!!!


Solution

  • The generated by default only supports numeric values, see H2 SQL Grammer and sequence option.

    I tested the SQL with a H2 database and the varchar(255) type is not supported with generated by default. This is the case for your ID field. Maybe you provide a value generator e.g. with @GeneratedValue(generator = "<name-of-a-generator").

    Starting with Hibernate Doc you could try to implement a custom generator. I found a short tutorial here. Maybe this prevents Hibernate from adding the generated by default.

    I replaced the varchar(255) with int and the SQL is valid:

    create table guest_boot_notification (id int generated by default
    as identity, link_id varchar(255), 
    notification_lang varchar(255) check (notification_lang in ('EN','GE','ZH','ZH_TW')), type varchar(255) check (type in ('CHAIR','CABINET','TABLE','SOFA')), 
    web_hook_url varchar(255), primary key (id))
    

    Another solution is described in this stackoverflow question.