Liquibase + Hibernate primary key name generation

We are using Liquibase’s diffChangelog command (via Gradle) to generate out changelog content based on our Spring Boot entities. I have it setup to use Hibernate and the camel case to underscore naming strategy. This mostly works as I would expect, except for constraints like the primary key, where it continues to be in camel case. Is there a configuration piece I’m missing or is this a gap in changelog generation? You can see in the output where it generates patientPK.

What’s interesting is that if I have Liquibase execute the changelog via Gradle (via update), it creates the table with the primary key as patientPK. If however I let Spring Boot run the changelog as part of its startup process it instead creates the constraint as patient_pkey. The later is more in line with what I would hope the Liquibase/Hibernate generate diff code would do.

For reference this is Spring Boot 3.2.0, Hiberate 6.3.1, Liquibase 4.25.0, Liquibase Gradle plug-in 2.2.0.

Here’s what that configuration looks like:

liquibase {
	activities {
		main {
			String targetFile = project.gradle.startParameter.taskNames.contains('liquibaseDiffChangelog') ? "db.changelog.diff.xml" : "/db/changelog/db.changelog-master.xml"
			driver 'org.postgresql.Driver'
			url System.getenv("JDBC_DATABASE_URL") ?: 'jdbc:postgresql://localhost:5432/sbdemo'
			//username 'postgres'
			//password ''
			changelogFile targetFile
			referenceDriver 'liquibase.ext.hibernate.database.connection.HibernateDriver'
			referenceUrl 'hibernate:spring:com.demo' +
					'?dialect=org.hibernate.dialect.PostgreSQLDialect' +
					'&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy' +

liquibaseDiff.dependsOn compileJava
liquibaseDiffChangelog.dependsOn compileJava

Here’s example output (trimmed):

    <changeSet author="..." id="...">
        <createTable tableName="patient">
            <column name="id" type="UUID">
                <constraints nullable="false" primaryKey="true" primaryKeyName="patientPK"/>
            <column name="birth_date" type="date"/>
            <column name="email" type="VARCHAR(255)"/>
            <column name="first_name" type="VARCHAR(50)">
                <constraints nullable="false"/>

Here’s the relevant logging output:

[2023-12-05 16:46:48] INFO [liquibase.ext] Reading hibernate configuration hibernate:spring:com.demo?dialect=org.hibernate.dialect.PostgreSQLDialect&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy&hibernate.physical_naming_strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
[2023-12-05 16:46:48] INFO [liquibase.ext] Found package com.demo
[2023-12-05 16:46:49] INFO [liquibase.ext] Using dialect org.hibernate.dialect.PostgreSQLDialect
[2023-12-05 16:46:49] INFO [liquibase.ext] Found table patient
[2023-12-05 16:46:49] INFO [liquibase.ext] Found table patient
[2023-12-05 16:46:49] INFO [liquibase.ext] Found table patient
[2023-12-05 16:46:49] INFO [liquibase.ext] Found primary key patientPK
[2023-12-05 16:46:49] INFO [liquibase.ext] Found column id uuid
[2023-12-05 16:46:49] INFO [liquibase.ext] Found column birth_date date
[2023-12-05 16:46:49] INFO [liquibase.ext] Found column created_at TIMESTAMP WITH TIME ZONE
[2023-12-05 16:46:49] INFO [liquibase.ext] Found column created_by varchar(255)
[2023-12-05 16:46:49] INFO [liquibase.ext] Found column email varchar(255)
[2023-12-05 16:46:49] INFO [liquibase.ext] Found column first_name varchar(50)
[2023-12-05 16:46:49] INFO [liquibase.ext] Found column last_name varchar(50)
[2023-12-05 16:46:49] INFO [liquibase.ext] Found column updated_at TIMESTAMP WITH TIME ZONE
[2023-12-05 16:46:49] INFO [liquibase.ext] Found column updated_by varchar(255)
[2023-12-05 16:46:49] INFO [liquibase.database] Set default schema name to public
[2023-12-05 16:46:49] INFO [liquibase.command] Diff command completed