Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fix-hibernate-6.2.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/test.yml
#	pom.xml
#	src/main/java/liquibase/ext/hibernate/snapshot/TableSnapshotGenerator.java
  • Loading branch information
filipelautert committed Sep 20, 2023
2 parents 838ca9d + 84ce993 commit 8047e55
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ updates:
- "sdou"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
directory: "/"
schedule:
interval: "daily"
3 changes: 1 addition & 2 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/attach-artifact-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion .github/workflows/release-published.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/snyk-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 15 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected].4
#uses: liquibase/build-logic/.github/workflows/[email protected].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
Expand Down Expand Up @@ -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: |
Expand All @@ -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: |
Expand All @@ -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'
Expand All @@ -116,13 +120,14 @@ 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: |
**/target/surefire-reports
**/target/jacoco.exec
dependabot:
uses: liquibase/build-logic/.github/workflows/dependabot-automerge.yml@main
needs: hibernate-test
uses: liquibase/build-logic/.github/workflows/[email protected]
secrets: inherit
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate6</artifactId>
<version>4.23.2-SNAPSHOT</version>
<version>4.24.2-SNAPSHOT</version>

<name>Liquibase Hibernate Integration</name>
<description>Liquibase extension for hibernate integration including generating changesets based on changed
Expand Down Expand Up @@ -69,8 +69,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hibernate.version>6.3.0.Final</hibernate.version>
<spring.version>6.0.11</spring.version>
<liquibase.version>4.23.0</liquibase.version>
<spring.version>6.0.12</spring.version>
<liquibase.version>4.23.2</liquibase.version>
<!--suppress UnresolvedMavenProperty -->
<liquibase.sdk.github.token>${env.GITHUB_TOKEN}</liquibase.sdk.github.token>
<sonar.organization>liquibase</sonar.organization>
Expand Down Expand Up @@ -149,13 +149,13 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.220</version>
<version>2.2.224</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -342,7 +342,7 @@
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.9.1.2184</version>
<version>3.10.0.2594</version>
</plugin>

<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Join> joins = pc.getJoins();
Iterator<Join> joinMappings = joins.iterator();
while (joinMappings.hasNext()) {
Join join = joinMappings.next();
addDatabaseObjectToSchema(join.getTable(), schema, snapshot);
}
}
}

Expand Down Expand Up @@ -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));
}
}
40 changes: 40 additions & 0 deletions src/test/java/com/example/ejb3/auction/FirstTable.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
19 changes: 19 additions & 0 deletions src/test/java/com/example/ejb3/auction/SecondTable.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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"));
}
}
1 change: 1 addition & 0 deletions src/test/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<class>com.example.ejb3.auction.Watcher</class>
<class>com.example.ejb3.auction.Item</class>
<class>com.example.ejb3.auction.AuditedItem</class>
<class>com.example.ejb3.auction.FirstTable</class>
<properties>
<property name="hibernate.cache.use_second_level_cache" value="false"/>
<property name="hibernate.archive.autodetection" value="false"/>
Expand Down

0 comments on commit 8047e55

Please sign in to comment.