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