Skip to content

Commit 8c8304a

Browse files
committed
HHH-8021 support overriding nested embeddables with secondary tables
1 parent 839f680 commit 8c8304a

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* JBoss, Home of Professional Open Source
5+
* Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors
6+
* as indicated by the @authors tag. All rights reserved.
7+
* See the copyright.txt in the distribution for a
8+
* full listing of individual contributors.
9+
*
10+
* This copyrighted material is made available to anyone wishing to use,
11+
* modify, copy, or redistribute it subject to the terms and conditions
12+
* of the GNU Lesser General Public License, v. 2.1.
13+
* This program is distributed in the hope that it will be useful, but WITHOUT A
14+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16+
* You should have received a copy of the GNU Lesser General Public License,
17+
* v.2.1 along with this distribution; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19+
* MA 02110-1301, USA.
20+
*/
21+
package org.hibernate.test.annotations.embeddables.nested;
22+
23+
import static org.junit.Assert.assertEquals;
24+
25+
import javax.persistence.AttributeOverride;
26+
import javax.persistence.AttributeOverrides;
27+
import javax.persistence.Column;
28+
import javax.persistence.Embeddable;
29+
import javax.persistence.Embedded;
30+
import javax.persistence.Entity;
31+
import javax.persistence.GeneratedValue;
32+
import javax.persistence.Id;
33+
import javax.persistence.SecondaryTable;
34+
import javax.persistence.SecondaryTables;
35+
import javax.persistence.Table;
36+
37+
import org.hibernate.Session;
38+
import org.hibernate.testing.TestForIssue;
39+
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
40+
import org.junit.Test;
41+
42+
/**
43+
* @author Brett Meyer
44+
*/
45+
public class NestedEmbeddableWithSecondaryTableTest extends BaseCoreFunctionalTestCase {
46+
47+
@Test
48+
@TestForIssue(jiraKey = "HHH-8021")
49+
public void testCase() {
50+
EntityA e = new EntityA();
51+
e.embedA.embedAttrA = "foo1";
52+
e.embedA.embedB.embedAttrB = "foo2";
53+
54+
Session s = openSession();
55+
s.getTransaction().begin();
56+
s.persist( e );
57+
s.getTransaction().commit();
58+
s.close();
59+
60+
s = openSession();
61+
s.getTransaction().begin();
62+
e = (EntityA) s.get( EntityA.class, e.id );
63+
assertEquals( "foo1", e.embedA.embedAttrA );
64+
assertEquals( "foo2", e.embedA.embedB.embedAttrB );
65+
s.getTransaction().commit();
66+
s.close();
67+
}
68+
69+
@Override
70+
protected Class<?>[] getAnnotatedClasses() {
71+
return new Class<?>[] { EntityA.class, EmbeddableA.class, EmbeddableB.class };
72+
}
73+
74+
@Entity
75+
@Table(name = "TableA")
76+
@SecondaryTables({ @SecondaryTable(name = "TableB") })
77+
public static class EntityA {
78+
79+
@Id
80+
@GeneratedValue
81+
public Integer id;
82+
83+
@Embedded
84+
@AttributeOverrides({ @AttributeOverride(name = "embedAttrA", column = @Column(table = "TableB")) })
85+
public EmbeddableA embedA = new EmbeddableA();
86+
}
87+
88+
@Embeddable
89+
public static class EmbeddableA {
90+
91+
@Embedded
92+
@AttributeOverrides({ @AttributeOverride(name = "embedAttrB", column = @Column(table = "TableB")) })
93+
public EmbeddableB embedB = new EmbeddableB();
94+
95+
public String embedAttrA;
96+
}
97+
98+
@Embeddable
99+
public static class EmbeddableB {
100+
101+
public String embedAttrB;
102+
}
103+
}

0 commit comments

Comments
 (0)