DDL generations differs between Spring Boot 2.x and 3.x when using UUID

Hey,

i recently created a Issue at the Spring Boot JPA repository on Github to explain a problem i encountered while upgrading from Spring Boot 2.x to 3.0.x over to 3.1.x and it seems to be a problem within Hibernate.

Im using the ddl-generation provided by Hibernate through Spring Boot.
For the Migration from Spring Boot 2.x. to 3.0.x i had to modify my Entities as following:

@Getter
@Setter
@Entity
public class Entity1 {

    @Id
    @Type(type = "uuid-char")
    private UUID id;

    private String field1;
    private String field2;
    private String field3;
}
@Getter
@Setter
@Entity
public class Entity1 {

    @Id
-    @Type(type = "uuid-char")
+   @JdbcTypeCode(SqlTypes.VARCHAR)
    private UUID id;

    private String field1;
    private String field2;
    private String field3;
}

The generated DDL-SQL already differs for those definitions between SB 2 and SB 3 like this:

Spring Boot 2.7.x:

create table entity1 (id varchar(255) not null, field1 varchar(255), field2 varchar(255), field3 varchar(255), primary key (id)) engine=InnoDB;

Spring Boot 3.x:

create table entity1 (id varchar(36) not null, field1 varchar(255), field2 varchar(255), field3 varchar(255), primary key (id)) engine=InnoDB;

Booting up the Spring Boot 3.0.x application had no impact on the database (im using update-mode) and the application booted up without any problems.

After upgrading to Spring Boot 3.1.x (which uses Hibernate 6.2 over Hibernate 6.1) the update-mode tries to modify (ALTER TABLE) all IDs with a smaller VARCHAR-datatype which fails due to some constraints.

I’d like to setup hibernate to ignore datatype lengths like it did with Spring Boot 3.0.x but i dont know how :smiley:

Spring Issue for ref: DDL generations differs between Spring Boot 3.0.x and 3.1.x when using UUID · Issue #3087 · spring-projects/spring-data-jpa · GitHub

Kings regards
SeaLife

There is no bug here. Hibernate just gives you the DDL needed to reach the state of your database schema that Hibernate expects. How you do the migration is up to you, and you will have to think about migration. The error you are getting is pretty clear Cannot change column 'id': used in a foreign key constraint 'FK8dpmsvheg2i2kn33cjbi5652n' of table 's19_govnet.appointment_registered_users'. Just drop the foreign key and re-create it after altering all the column types.

Thank you, i tried what u suggested using:

SELECT concat('ALTER TABLE `', TABLE_NAME, '` DROP FOREIGN KEY `', CONSTRAINT_NAME, '`;')
FROM information_schema.key_column_usage
WHERE CONSTRAINT_SCHEMA = 's19_govnet'
AND referenced_table_name IS NOT NULL;

Running all those statemens and bootup the application. All columns were modified without any problem and the foreign keys were added back by the application.

Thank you, running now on spring boot 3.1. without any problems <3