From 2c5e0ff1131990ddc0b15201b53c1979d882ee3c Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 19 Nov 2024 15:25:16 -0600 Subject: [PATCH] HHH-12676 - SecondaryTables do not work with TABLE_PER_CLASS inheritance --- .../secondarytables/CardPayment.java | 27 +++++++++++++++++ .../secondarytables/Payment.java | 21 +++++++++++++ .../UnionSubclassWithSecondaryTableTests.java | 30 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass/secondarytables/CardPayment.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass/secondarytables/Payment.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass/secondarytables/UnionSubclassWithSecondaryTableTests.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass/secondarytables/CardPayment.java b/hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass/secondarytables/CardPayment.java new file mode 100644 index 0000000000..e91a9e1193 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass/secondarytables/CardPayment.java @@ -0,0 +1,27 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.orm.test.unionsubclass.secondarytables; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.PrimaryKeyJoinColumn; +import jakarta.persistence.SecondaryTable; + +import java.time.ZonedDateTime; + +/** + * @author Steve Ebersole + */ +@Entity +@SecondaryTable( + name = "authorizations", + pkJoinColumns = @PrimaryKeyJoinColumn(name = "charge_auth_fk", referencedColumnName = "id") +) +public class CardPayment extends Payment { + ZonedDateTime paymentMade; + + @Column(table = "authorizations") + String authorizationCode; +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass/secondarytables/Payment.java b/hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass/secondarytables/Payment.java new file mode 100644 index 0000000000..4fdf6b9840 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass/secondarytables/Payment.java @@ -0,0 +1,21 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.orm.test.unionsubclass.secondarytables; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Inheritance; +import jakarta.persistence.InheritanceType; + +/** + * @author Steve Ebersole + */ +@Entity +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +public abstract class Payment { + @Id + private Integer id; + private String note; +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass/secondarytables/UnionSubclassWithSecondaryTableTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass/secondarytables/UnionSubclassWithSecondaryTableTests.java new file mode 100644 index 0000000000..e9449bf0bd --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/unionsubclass/secondarytables/UnionSubclassWithSecondaryTableTests.java @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.orm.test.unionsubclass.secondarytables; + +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.FailureExpected; +import org.hibernate.testing.orm.junit.Jira; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("JUnitMalformedDeclaration") +@DomainModel(annotatedClasses = {Payment.class, CardPayment.class}) +@SessionFactory +public class UnionSubclassWithSecondaryTableTests { + @Test + @FailureExpected + @Jira("https://hibernate.atlassian.net/browse/HHH-12676") + void testIt(SessionFactoryScope sessions) { + sessions.inTransaction( (session) -> { + session.createQuery( "from CardPayment" ).getResultList(); + session.createQuery( "from Payment" ).getResultList(); + } ); + } +}