|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 | + * Copyright Red Hat Inc. and Hibernate Authors |
| 4 | + */ |
| 5 | +package org.hibernate.orm.test.query.sql; |
| 6 | + |
| 7 | + |
| 8 | +import org.hibernate.testing.orm.junit.DomainModel; |
| 9 | +import org.hibernate.testing.orm.junit.JiraKey; |
| 10 | +import org.hibernate.testing.orm.junit.SessionFactory; |
| 11 | +import org.hibernate.testing.orm.junit.SessionFactoryScope; |
| 12 | +import org.junit.jupiter.api.Test; |
| 13 | + |
| 14 | +import jakarta.persistence.Entity; |
| 15 | +import jakarta.persistence.Id; |
| 16 | +import jakarta.persistence.Inheritance; |
| 17 | +import jakarta.persistence.InheritanceType; |
| 18 | + |
| 19 | +/** |
| 20 | + * @author Yanming Zhou |
| 21 | + */ |
| 22 | +@JiraKey( "HHH-18610" ) |
| 23 | +@DomainModel(annotatedClasses = { |
| 24 | + NativeQueryWithInheritanceTests.SingleTableParent.class, |
| 25 | + NativeQueryWithInheritanceTests.TablePerClassParent.class, |
| 26 | + NativeQueryWithInheritanceTests.JoinedParent.class, |
| 27 | + NativeQueryWithInheritanceTests.SingleTableChild.class, |
| 28 | + NativeQueryWithInheritanceTests.TablePerClassChild.class, |
| 29 | + NativeQueryWithInheritanceTests.JoinedChild.class |
| 30 | +}) |
| 31 | +@SessionFactory |
| 32 | +public class NativeQueryWithInheritanceTests { |
| 33 | + |
| 34 | + @Test |
| 35 | + public void testSingleTable(SessionFactoryScope scope) { |
| 36 | + scope.inTransaction( (session) -> { |
| 37 | + session.createNativeQuery("select {p.*} from SingleTableParent p") |
| 38 | + .addEntity( "p", SingleTableParent.class ).list(); |
| 39 | + } ); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void testTablePerClass(SessionFactoryScope scope) { |
| 44 | + scope.inTransaction( (session) -> { |
| 45 | + session.createNativeQuery("select {p.*} from TablePerClassParent p") |
| 46 | + .addEntity( "p", TablePerClassParent.class ).list(); |
| 47 | + } ); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testJoined(SessionFactoryScope scope) { |
| 52 | + scope.inTransaction( (session) -> { |
| 53 | + session.createNativeQuery("select {p.*} from JoinedParent p") |
| 54 | + .addEntity( "p", JoinedParent.class ).list(); |
| 55 | + } ); |
| 56 | + } |
| 57 | + |
| 58 | + @Entity(name = "SingleTableParent") |
| 59 | + @Inheritance(strategy = InheritanceType.SINGLE_TABLE) |
| 60 | + static class SingleTableParent { |
| 61 | + @Id |
| 62 | + Long id; |
| 63 | + } |
| 64 | + |
| 65 | + @Entity(name = "SingleTableChild") |
| 66 | + static class SingleTableChild extends SingleTableParent { |
| 67 | + } |
| 68 | + |
| 69 | + @Entity(name = "TablePerClassParent") |
| 70 | + @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) |
| 71 | + static class TablePerClassParent { |
| 72 | + @Id |
| 73 | + Long id; |
| 74 | + } |
| 75 | + |
| 76 | + @Entity(name = "TablePerClassChild") |
| 77 | + static class TablePerClassChild extends TablePerClassParent { |
| 78 | + } |
| 79 | + |
| 80 | + @Entity(name = "JoinedParent") |
| 81 | + @Inheritance(strategy = InheritanceType.JOINED) |
| 82 | + static class JoinedParent { |
| 83 | + @Id |
| 84 | + Long id; |
| 85 | + } |
| 86 | + |
| 87 | + @Entity(name = "JoinedChild") |
| 88 | + static class JoinedChild extends JoinedParent { |
| 89 | + } |
| 90 | +} |
0 commit comments