Skip to content

Commit 1ad86f7

Browse files
committed
HHH-15235 Add test for issue
1 parent a62ca31 commit 1ad86f7

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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.test.annotations.onetoone;
8+
9+
import java.io.Serializable;
10+
11+
import org.hibernate.testing.TestForIssue;
12+
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
13+
14+
import javax.persistence.CascadeType;
15+
import javax.persistence.Embeddable;
16+
import javax.persistence.EmbeddedId;
17+
import javax.persistence.Entity;
18+
import javax.persistence.JoinColumn;
19+
import javax.persistence.OneToOne;
20+
import javax.persistence.Table;
21+
22+
import org.junit.Test;
23+
24+
@TestForIssue(jiraKey = "HHH-15235")
25+
public class EmbeddedIdTest extends BaseCoreFunctionalTestCase {
26+
27+
@Override
28+
protected Class<?>[] getAnnotatedClasses() {
29+
return new Class[] { Bar.class, Foo.class };
30+
}
31+
32+
@Test
33+
public void testMerge() {
34+
inTransaction(
35+
session -> {
36+
FooId fooId = new FooId();
37+
fooId.id = "foo";
38+
Foo foo = new Foo();
39+
foo.id = fooId;
40+
Bar bar = new Bar();
41+
BarId barId = new BarId();
42+
barId.id = 1l;
43+
bar.id = barId;
44+
foo.bar = bar;
45+
bar.foo = foo;
46+
session.merge( foo );
47+
session.flush();
48+
}
49+
);
50+
}
51+
52+
@Embeddable
53+
public static class BarId implements Serializable {
54+
private Long id;
55+
}
56+
57+
@Embeddable
58+
public static class FooId implements Serializable {
59+
private String id;
60+
}
61+
62+
@Entity(name = "Bar")
63+
@Table(name = "BAR_TABLE")
64+
public static class Bar {
65+
@EmbeddedId
66+
private BarId id;
67+
68+
private String name;
69+
70+
@OneToOne(mappedBy = "bar")
71+
private Foo foo;
72+
}
73+
74+
@Entity(name = "Foo")
75+
@Table(name = "FOO_TABLE")
76+
public static class Foo {
77+
@EmbeddedId
78+
private FooId id;
79+
80+
private String name;
81+
82+
@OneToOne(cascade = CascadeType.ALL)
83+
@JoinColumn(name = "bar_id")
84+
private Bar bar;
85+
}
86+
}

0 commit comments

Comments
 (0)