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

Liquibase 4.28 + hibernate 6 / Spring: Diff does not output changes #708

Open
vigier opened this issue Aug 2, 2024 · 4 comments
Open

Liquibase 4.28 + hibernate 6 / Spring: Diff does not output changes #708

vigier opened this issue Aug 2, 2024 · 4 comments

Comments

@vigier
Copy link

vigier commented Aug 2, 2024

Hello,
I recognize a changed behaviour using mvn liquiebase:diff when switching from version 4.26 to 4.28:

When modifying a @Column annotation I usually see a drop-column and an add-column change in the diff. Now only the drop-column appears.

After debugging a while I see that DiffOutputControl.shouldOutput returns now false for the add-column modification because the compared catalog name is different in liquibase 4.28:

  • with 4.26 they are 2 times "DEFAULT.DEFAULT" --> result is true
  • with 4.28: "hibernate.DEFAULT" & "DEFAULT.DEFAULT" --> result is false

Database: admin @ jdbc:postgresql://localhost:5432/my_db (Default Schema: public)
ReferenceUrl in liquibase.properties: referenceUrl=hibernate:spring:com.bosch.some-example.data.model?dialect=org.hibernate.dialect.PostgresPlusDialect

Versions used:

        <java.version>21</java.version>
        <liquibase.version>4.28.0</liquibase.version>
        <springboot.version>3.3.2</springboot.version>
        <postgresql.version>42.7.2</postgresql.version>
        <hibernate.version>6.5.2.Final</hibernate.version>

I did not yet drill down to the source of the issue - why the catalog name for the reference changed. Maybe you can confirm the issue and give me a hint where to look?

Thanks!

@vigier vigier changed the title Liquibase Diff 4.28 + hibernate6 / Spring does not output changes Liquibase 4.28 + hibernate 6 / Spring: Diff does not output changes Aug 2, 2024
@vigier
Copy link
Author

vigier commented Aug 5, 2024

Might be same as: liquibase/liquibase#6148

@lorenzbaier
Copy link
Contributor

lorenzbaier commented Aug 6, 2024

i think I found the commit which breaks this liquibase/liquibase@2b1c363 in SnapshotControl (where the types are filtered liquibase/liquibase@2b1c363#diff-8103e5b2a72eeba8cd3b9dbd302a1e3199c99fb2eebb8f5de71b817424f74aaeR133)
this doesn't work together with

because then the CatalogSnapshotGenerator (
return new Catalog(snapshot.getDatabase().getDefaultCatalogName()).setDefault(true);
) is not called and not set to default true

Maybe you could set the catalog to default in

return new Schema(snapshot.getDatabase().getDefaultCatalogName(), snapshot.getDatabase().getDefaultSchemaName()).setDefault(true);

@Guschtel
Copy link
Contributor

Guschtel commented Sep 17, 2024

Easiest Fix that I found so far was to change HibernateSpringPackageDatabase so that the schema and catalog both return null instead of "HIBERNATE":

Index: src/main/java/liquibase/ext/hibernate/database/HibernateSpringPackageDatabase.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/liquibase/ext/hibernate/database/HibernateSpringPackageDatabase.java b/src/main/java/liquibase/ext/hibernate/database/HibernateSpringPackageDatabase.java
--- a/src/main/java/liquibase/ext/hibernate/database/HibernateSpringPackageDatabase.java	(revision da50f6551d375df5f53dfddb0c0d7f335abcbb2f)
+++ b/src/main/java/liquibase/ext/hibernate/database/HibernateSpringPackageDatabase.java	(date 1726589106159)
@@ -26,6 +26,16 @@
  */
 public class HibernateSpringPackageDatabase extends JpaPersistenceDatabase {
 
+    @Override
+    public String getDefaultCatalogName() {
+        return null;
+    }
+
+    @Override
+    public String getDefaultSchemaName() {
+        return null;
+    }
+
     @Override
     public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException {
         return conn.getURL().startsWith("hibernate:spring:") && !isXmlFile(conn);

But I'm not sure about the implications of that.
Basically you can clone the project, change these two Methods and use your patched version of the library.
Changesets will be generated again with this.

@Guschtel
Copy link
Contributor

I've found a much better fix I think:

Index: src/main/java/liquibase/ext/hibernate/database/HibernateDatabase.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/liquibase/ext/hibernate/database/HibernateDatabase.java b/src/main/java/liquibase/ext/hibernate/database/HibernateDatabase.java
--- a/src/main/java/liquibase/ext/hibernate/database/HibernateDatabase.java	(revision da50f6551d375df5f53dfddb0c0d7f335abcbb2f)
+++ b/src/main/java/liquibase/ext/hibernate/database/HibernateDatabase.java	(date 1726727111206)
@@ -331,7 +331,7 @@
 
     @Override
     public boolean supportsCatalogs() {
-        return false;
+        return true;
     }
 
     /**

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

5 participants