Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong column type generated with diffChangelog #655

Open
aepshteyn opened this issue Feb 4, 2024 · 0 comments
Open

Wrong column type generated with diffChangelog #655

aepshteyn opened this issue Feb 4, 2024 · 0 comments

Comments

@aepshteyn
Copy link

aepshteyn commented Feb 4, 2024

I'm using liquibase-hibernate5-4.25.1 with a hibernate:ejb3:... referenceUrl.

In my java source code I removed a nullable = false attribute from a @Column annotation on an entity field like this:

  @Column(columnDefinition = "binary(32)", length = 32/* nullable = false*/)
  private byte[] passwordHash;

After making the above modification, I ran liquibase diff-changelog and got the following changeset:

  <changeSet author="Alex (generated)" id="1706924110096-1">
    <dropNotNullConstraint columnDataType="blob(32)" columnName="passwordHash" tableName="User"/>
  </changeSet>

This is wrong because the actual column type is binary(32), but the generated changeSet uses blob(32), which results in the following update SQL:

--  Changeset changelog-0.1.mysql.xml::1706924110096-1::Alex (generated)
ALTER TABLE snake.User MODIFY passwordHash BLOB NULL;

Applying this change to the (MySQL) database changed the column type from binary(32) to blob, and this, in turn, causes the Hibernate schema validation ("hibernate.hbm2ddl.auto"="validate") to fail at runtime:

org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [passwordHash] in table [User]; found [blob (Types#LONGVARBINARY)], but expecting [binary(32) (Types#VARBINARY)]

I suspect that the liquibase-hibernate plugin is failing to correctly parse the columnDefinition attribute of the JPA @Column annotation.

For your reference, my baseline changelog generated with liquibase generateChangeLog against the pre-migration database schema (created by Hibernate with "hibernate.hbm2ddl.auto"="create") from the original JPA source code (before I removed the nullable = false constraint) does have the correct column type:

<createTable tableName="user">
   ...
    <column name="passwordHash" type="BINARY(32)">
        <constraints nullable="false"/>
    </column>
    ...
</createTable>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants