Generate ddl every time at startup

like this, The ddl is applied every time the application starts, even if the table structure has not changed.

alter table sys_user modify column sex  enum ('FEMALE','MALE')

configuration:

hibernate.hbm2ddl.auto=update

database: mysql8.0
driver: mysql8.0
hibernate: 6.2.2

After debugging and troubleshooting, I found that the real column size is inconsistent with the column size in the entity class, so every time I modify the table structure.

The enumeration column size returned by mysql driver is 6,hibernate the column size is calculated by the default value of the varchar type, 255,255 and 6 are not equal, so each time the alter.

In fact, I think enumeration types do not need to judge whether the size is consistent, and this problem will also occur in datetime and bigint, datetime I handled this problem through custom dialect. I also don’t know how mysql calculates the column size for enumeration and bigint types, because he read the data in the information_schema.column table.

see also
org.hibernate.tool.schema.internal.ColumnDefinitions#hasMatchingLength

Did you try updating to Hibernate 6.2.7.Final yet?

6.2.7.Final version this problem still exists

In that case, please create an issue in the issue tracker(https://hibernate.atlassian.net) with a test case(https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) that reproduces the issue.

ok,issue is created.
https://hibernate.atlassian.net/browse/HHH-17011

1 Like