Skip to content

Commit 914a2c5

Browse files
committed
HHH-15235 Add test for issue
1 parent ddf0cb7 commit 914a2c5

File tree

1 file changed

+90
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)