Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!!!

like image 956
jetpack Avatar asked Dec 06 '25 13:12

jetpack


1 Answers

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.

like image 156
Easterwood Avatar answered Dec 08 '25 07:12

Easterwood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!