|
| 1 | +/* |
| 2 | + * Hibernate, Relational Persistence for Idiomatic Java |
| 3 | + * |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
| 5 | + * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
| 6 | + */ |
| 7 | +package org.hibernate.persister.entity; |
| 8 | + |
| 9 | +import jakarta.persistence.Entity; |
| 10 | +import jakarta.persistence.GeneratedValue; |
| 11 | +import jakarta.persistence.Id; |
| 12 | +import jakarta.persistence.Inheritance; |
| 13 | +import jakarta.persistence.Table; |
| 14 | +import org.hibernate.metamodel.MappingMetamodel; |
| 15 | +import org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl; |
| 16 | +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; |
| 17 | +import org.hibernate.testing.orm.junit.JiraKey; |
| 18 | +import org.hibernate.testing.orm.junit.Jpa; |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | + |
| 21 | +import static jakarta.persistence.InheritanceType.JOINED; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 23 | + |
| 24 | +/** |
| 25 | + * @author Vincent Bouthinon |
| 26 | + */ |
| 27 | +@Jpa( |
| 28 | + annotatedClasses = { |
| 29 | + JoinedSubclassEntityPersisterTest.Animal.class, |
| 30 | + JoinedSubclassEntityPersisterTest.Dog.class, |
| 31 | + } |
| 32 | +) |
| 33 | +@JiraKey("HHH-18703") |
| 34 | +class JoinedSubclassEntityPersisterTest { |
| 35 | + |
| 36 | + @Test |
| 37 | + void the_table_name_must_match_the_attribute_s_column(EntityManagerFactoryScope scope) { |
| 38 | + scope.inTransaction( |
| 39 | + entityManager -> { |
| 40 | + JpaMetamodelImpl metamodel = (JpaMetamodelImpl) entityManager.getMetamodel(); |
| 41 | + MappingMetamodel mappingMetamodel = metamodel.getMappingMetamodel(); |
| 42 | + AbstractEntityPersister entityDescriptor = (AbstractEntityPersister) mappingMetamodel.getEntityDescriptor( Dog.class ); |
| 43 | + String table = entityDescriptor.getTableName( entityDescriptor.determineTableNumberForColumn( "name" ) ); |
| 44 | + assertEquals( "TANIMAL", table ); |
| 45 | + } |
| 46 | + ); |
| 47 | + } |
| 48 | + |
| 49 | + @Entity |
| 50 | + @Inheritance(strategy = JOINED) |
| 51 | + @Table(name = "TANIMAL") |
| 52 | + public static class Animal { |
| 53 | + |
| 54 | + @Id |
| 55 | + @GeneratedValue |
| 56 | + public Integer id; |
| 57 | + |
| 58 | + private String name; |
| 59 | + |
| 60 | + public String getName() { |
| 61 | + return name; |
| 62 | + } |
| 63 | + |
| 64 | + public void setName(String name) { |
| 65 | + this.name = name; |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + @Entity |
| 70 | + @Table(name = "TDOG") |
| 71 | + public static class Dog extends Animal { |
| 72 | + |
| 73 | + } |
| 74 | +} |
0 commit comments