Skip to content

Commit 6a43fea

Browse files
Vincent Bouthinonsebersole
authored andcommitted
HHH-19272 : Secondary table with nested @Embedded object
https://hibernate.atlassian.net/browse/HHH-19272
1 parent 151e5d7 commit 6a43fea

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.mapping.embeddable;
6+
7+
import jakarta.persistence.AttributeOverride;
8+
import jakarta.persistence.Column;
9+
import jakarta.persistence.Embeddable;
10+
import jakarta.persistence.Embedded;
11+
import jakarta.persistence.Entity;
12+
import jakarta.persistence.GeneratedValue;
13+
import jakarta.persistence.Id;
14+
import jakarta.persistence.SecondaryTable;
15+
import jakarta.persistence.Table;
16+
import org.hibernate.cfg.JdbcSettings;
17+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
18+
import org.hibernate.testing.orm.junit.JiraKey;
19+
import org.hibernate.testing.orm.junit.Jpa;
20+
import org.hibernate.testing.orm.junit.Setting;
21+
import org.junit.jupiter.api.Test;
22+
23+
/**
24+
* Test passes if Author#name is renamed to Author#aname because it will be read before house (alphabetical order).
25+
* The issue occurs if the nested embedded is read first, due to the table calculation (ComponentPropertyHolder#addProperty) used by the embedded, which retrieves the table from the first property.
26+
*
27+
* @author Vincent Bouthinon
28+
*/
29+
@Jpa(
30+
annotatedClasses = {
31+
NestedEmbeddedObjectWithASecondaryTableTest.Author.class,
32+
NestedEmbeddedObjectWithASecondaryTableTest.Book.class,
33+
NestedEmbeddedObjectWithASecondaryTableTest.House.class
34+
},
35+
integrationSettings = @Setting(name = JdbcSettings.SHOW_SQL, value = "true")
36+
)
37+
@JiraKey("HHH-19272")
38+
class NestedEmbeddedObjectWithASecondaryTableTest {
39+
40+
@Test
41+
void testExceptionEmbeddedHasPropertiesMappedToTwoDifferentTables(EntityManagerFactoryScope scope) {
42+
43+
scope.inTransaction(
44+
entityManager -> {
45+
// Nothing
46+
}
47+
);
48+
}
49+
50+
@Entity(name = "book")
51+
@Table(name = "TBOOK")
52+
@SecondaryTable(name = "TSECONDARYTABLE")
53+
public static class Book {
54+
55+
@Id
56+
@GeneratedValue
57+
private Long id;
58+
59+
@AttributeOverride(name = "name", column = @Column(name = "authorName", table = "TSECONDARYTABLE"))
60+
@Embedded
61+
private Author author;
62+
63+
}
64+
65+
@Embeddable
66+
public static class Author {
67+
68+
@AttributeOverride(name = "name", column = @Column(name = "houseName", table = "TSECONDARYTABLE"))
69+
@Embedded
70+
private House house;
71+
72+
private String name;
73+
}
74+
75+
@Embeddable
76+
public static class House {
77+
private String name;
78+
}
79+
}

0 commit comments

Comments
 (0)