diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 4d3997d0..3979ebc6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,6 +9,6 @@ updates: - "sdou" - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "daily" \ No newline at end of file + directory: "/" + schedule: + interval: "daily" diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index d9e7354f..e02868da 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -49,5 +49,4 @@ template: | $CHANGES - **Full Changelog**: https://github.com/liquibase/liquibase-mongodb/compare/liquibase-mongodb-$PREVIOUS_TAG...liquibase-mongodb-$RESOLVED_VERSION - + **Full Changelog**: https://github.com/liquibase/liquibase-hibernate/compare/$PREVIOUS_TAG...$RESOLVED_VERSION diff --git a/.github/workflows/attach-artifact-release.yml b/.github/workflows/attach-artifact-release.yml index f7a98def..90febfe7 100644 --- a/.github/workflows/attach-artifact-release.yml +++ b/.github/workflows/attach-artifact-release.yml @@ -8,5 +8,5 @@ on: jobs: attach-artifact-to-release: - uses: liquibase/build-logic/.github/workflows/extension-attach-artifact-release.yml@v0.3.4 + uses: liquibase/build-logic/.github/workflows/extension-attach-artifact-release.yml@v0.4.3 secrets: inherit diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 29b53632..12391ee6 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -5,7 +5,11 @@ on: branches: - main +permissions: + contents: write + pull-requests: write + jobs: create-release: - uses: liquibase/build-logic/.github/workflows/create-release.yml@v0.3.4 + uses: liquibase/build-logic/.github/workflows/create-release.yml@v0.4.3 secrets: inherit diff --git a/.github/workflows/release-published.yml b/.github/workflows/release-published.yml index fd344120..83333ba7 100644 --- a/.github/workflows/release-published.yml +++ b/.github/workflows/release-published.yml @@ -5,7 +5,11 @@ on: release: types: [published] +permissions: + contents: write + pull-requests: write + jobs: release: - uses: liquibase/build-logic/.github/workflows/extension-release-published.yml@v0.3.4 + uses: liquibase/build-logic/.github/workflows/extension-release-published.yml@v0.4.3 secrets: inherit diff --git a/.github/workflows/snyk-nightly.yml b/.github/workflows/snyk-nightly.yml index afa61ad2..c521acdb 100644 --- a/.github/workflows/snyk-nightly.yml +++ b/.github/workflows/snyk-nightly.yml @@ -10,5 +10,5 @@ on: jobs: security-scan: - uses: liquibase/build-logic/.github/workflows/synk-nightly.yml@v0.3.4 + uses: liquibase/build-logic/.github/workflows/synk-nightly.yml@v0.4.3 secrets: inherit \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b5235658..fa7e5f0b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,15 +8,19 @@ on: - reopened - synchronize +permissions: + contents: write + pull-requests: write + jobs: build: # This extension can not execute hibernete tests on Java 8/11. This needs to be fixed and then uncomment the following 2 lines and remove the build and unit-test logic from here - #uses: liquibase/build-logic/.github/workflows/os-extension-test.yml@v0.3.4 + #uses: liquibase/build-logic/.github/workflows/os-extension-test.yml@v0.3.5 #secrets: inherit name: Build & Package runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK 17 uses: actions/setup-java@v3 @@ -59,17 +63,17 @@ jobs: java: [ 17, 19 ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: ${{ matrix.java }} distribution: 'temurin' cache: 'maven' - name: Build Cache - uses: actions/cache@v3.0.5 + uses: actions/cache@v3.3.2 with: key: build-${{ github.run_number }}-${{ github.run_attempt }} path: | @@ -81,7 +85,7 @@ jobs: - name: Archive Test Results if: ${{ always() }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: test-reports-jdk-${{ matrix.java }} path: | @@ -99,10 +103,10 @@ jobs: hibernate: [ "6.0.2.Final", "6.1.7.Final" ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: 17 distribution: 'temurin' @@ -116,7 +120,7 @@ jobs: - name: Archive Test Results if: ${{ always() }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: test-reports-hibernate-${{ matrix.hibernate }} path: | @@ -124,5 +128,6 @@ jobs: **/target/jacoco.exec dependabot: - uses: liquibase/build-logic/.github/workflows/dependabot-automerge.yml@main + needs: hibernate-test + uses: liquibase/build-logic/.github/workflows/dependabot-automerge.yml@v0.4.3 secrets: inherit diff --git a/pom.xml b/pom.xml index 527bf9ed..4459353e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.liquibase.ext liquibase-hibernate6 - 4.23.2-SNAPSHOT + 4.24.2-SNAPSHOT Liquibase Hibernate Integration Liquibase extension for hibernate integration including generating changesets based on changed @@ -69,8 +69,8 @@ UTF-8 6.3.0.Final - 6.0.11 - 4.23.0 + 6.0.12 + 4.23.2 ${env.GITHUB_TOKEN} liquibase @@ -149,13 +149,13 @@ org.yaml snakeyaml - 2.0 + 2.2 test com.h2database h2 - 2.2.220 + 2.2.224 test @@ -342,7 +342,7 @@ org.sonarsource.scanner.maven sonar-maven-plugin - 3.9.1.2184 + 3.10.0.2594 diff --git a/src/main/java/liquibase/ext/hibernate/snapshot/TableSnapshotGenerator.java b/src/main/java/liquibase/ext/hibernate/snapshot/TableSnapshotGenerator.java index 29e875fb..18ad4e65 100644 --- a/src/main/java/liquibase/ext/hibernate/snapshot/TableSnapshotGenerator.java +++ b/src/main/java/liquibase/ext/hibernate/snapshot/TableSnapshotGenerator.java @@ -11,6 +11,8 @@ import liquibase.structure.core.Schema; import liquibase.structure.core.Table; import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.id.IdentifierGenerator; +import org.hibernate.mapping.Join; import org.hibernate.generator.Generator; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.RootClass; @@ -69,10 +71,14 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro org.hibernate.mapping.Table hibernateTable = pc.getTable(); if (hibernateTable.isPhysicalTable()) { - Table table = new Table().setName(hibernateTable.getName()); - table.setSchema(schema); - Scope.getCurrentScope().getLog(getClass()).info("Found table " + table.getName()); - schema.addDatabaseObject(snapshotObject(table, snapshot)); + addDatabaseObjectToSchema(hibernateTable, schema, snapshot); + + Collection joins = pc.getJoins(); + Iterator joinMappings = joins.iterator(); + while (joinMappings.hasNext()) { + Join join = joinMappings.next(); + addDatabaseObjectToSchema(join.getTable(), schema, snapshot); + } } } @@ -102,12 +108,16 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro org.hibernate.mapping.Collection coll = collIter.next(); org.hibernate.mapping.Table hTable = coll.getCollectionTable(); if (hTable.isPhysicalTable()) { - Table table = new Table().setName(hTable.getName()); - table.setSchema(schema); - Scope.getCurrentScope().getLog(getClass()).info("Found table " + table.getName()); - schema.addDatabaseObject(snapshotObject(table, snapshot)); + addDatabaseObjectToSchema(hTable, schema, snapshot); } } } } + + private void addDatabaseObjectToSchema(org.hibernate.mapping.Table join, Schema schema, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { + Table joinTable = new Table().setName(join.getName()); + joinTable.setSchema(schema); + Scope.getCurrentScope().getLog(getClass()).info("Found table " + joinTable.getName()); + schema.addDatabaseObject(snapshotObject(joinTable, snapshot)); + } } diff --git a/src/test/java/com/example/ejb3/auction/FirstTable.java b/src/test/java/com/example/ejb3/auction/FirstTable.java new file mode 100644 index 00000000..b6209706 --- /dev/null +++ b/src/test/java/com/example/ejb3/auction/FirstTable.java @@ -0,0 +1,40 @@ +package com.example.ejb3.auction; + +import jakarta.persistence.*; + +@Entity +@SecondaryTable(name = "second_table", pkJoinColumns = @PrimaryKeyJoinColumn(name = "first_table_id")) +public class FirstTable { + @Id + private Long id; + + @Column(name = "name") + private String name; + + @Embedded + private SecondTable secondTable; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public SecondTable getSecondTable() { + return secondTable; + } + + public void setSecondTable(SecondTable secondTable) { + this.secondTable = secondTable; + } +} diff --git a/src/test/java/com/example/ejb3/auction/SecondTable.java b/src/test/java/com/example/ejb3/auction/SecondTable.java new file mode 100644 index 00000000..9bc408d5 --- /dev/null +++ b/src/test/java/com/example/ejb3/auction/SecondTable.java @@ -0,0 +1,19 @@ +package com.example.ejb3.auction; + +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; + +@Embeddable +public class SecondTable { + + @Column(table = "second_table") + private String secondName; + + public String getSecondName() { + return secondName; + } + + public void setSecondName(String secondName) { + this.secondName = secondName; + } +} diff --git a/src/test/java/liquibase/ext/hibernate/database/HibernateEjb3DatabaseTest.java b/src/test/java/liquibase/ext/hibernate/database/HibernateEjb3DatabaseTest.java index 122963bd..f1b83920 100644 --- a/src/test/java/liquibase/ext/hibernate/database/HibernateEjb3DatabaseTest.java +++ b/src/test/java/liquibase/ext/hibernate/database/HibernateEjb3DatabaseTest.java @@ -55,7 +55,9 @@ public static void assertEjb3HibernateMapped(DatabaseSnapshot snapshot) { hasProperty("name", is("AuditedItem")), hasProperty("name", is("AuditedItem_AUD")), hasProperty("name", is("REVINFO")), - hasProperty("name", is("WatcherSeqTable")))); + hasProperty("name", is("WatcherSeqTable")), + hasProperty("name", is("FirstTable")), + hasProperty("name", is("second_table")))); Table bidTable = (Table) snapshot.get(new Table().setName("bid").setSchema(new Schema())); @@ -90,5 +92,12 @@ public static void assertEjb3HibernateMapped(DatabaseSnapshot snapshot) { hasProperty("primaryKeyTable", hasProperty("name", is("User"))) ) )); + + Table secondTable = (Table) snapshot.get(new Table().setName("second_table").setSchema(new Schema())); + assertThat(secondTable.getColumns(), containsInAnyOrder( + hasProperty("name", is("first_table_id")), + hasProperty("name", is("secondName")) + )); + assertThat(secondTable.getPrimaryKey().getColumnNames(), is("first_table_id")); } } diff --git a/src/test/resources/META-INF/persistence.xml b/src/test/resources/META-INF/persistence.xml index 99069fad..57a1e34b 100644 --- a/src/test/resources/META-INF/persistence.xml +++ b/src/test/resources/META-INF/persistence.xml @@ -12,6 +12,7 @@ com.example.ejb3.auction.Watcher com.example.ejb3.auction.Item com.example.ejb3.auction.AuditedItem + com.example.ejb3.auction.FirstTable