HHH-12676 - SecondaryTables do not work with TABLE_PER_CLASS inheritance

This commit is contained in:
Steve Ebersole 2024-11-19 15:25:16 -06:00
parent 1b9f636114
commit 2c5e0ff113
3 changed files with 78 additions and 0 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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();
} );
}
}