Skip to content

Commit 176b664

Browse files
Vincent Bouthinonbeikov
authored andcommitted
HHH-18703 : The JoinedSubclassEntityPersister#getTableNameForColumn method does not return the correct table in the JOINED inheritance strategy.
Cause: one uses a sorted set of tables, the other does not.
1 parent c698b8a commit 176b664

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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

Comments
 (0)