Skip to content

Commit b63376b

Browse files
committed
HHH-15235 Add test for issue
1 parent f7fc891 commit b63376b

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
25+
@TestForIssue(jiraKey = "HHH-15235")
26+
@DomainModel(
27+
annotatedClasses = {
28+
EmbeddedIdTest.Bar.class,
29+
EmbeddedIdTest.Foo.class
30+
}
31+
)
32+
@SessionFactory
33+
public class EmbeddedIdTest {
34+
35+
@Test
36+
public void testMerge(SessionFactoryScope scope) {
37+
scope.inTransaction(
38+
session -> {
39+
FooId fooId = new FooId();
40+
fooId.id = "foo";
41+
Foo foo = new Foo();
42+
foo.id = fooId;
43+
Bar bar = new Bar();
44+
BarId barId = new BarId();
45+
barId.id = 1l;
46+
bar.id = barId;
47+
foo.bar = bar;
48+
bar.foo = foo;
49+
session.merge( foo );
50+
session.flush();
51+
}
52+
);
53+
}
54+
55+
@Embeddable
56+
public static class BarId implements Serializable {
57+
private Long id;
58+
}
59+
60+
@Embeddable
61+
public static class FooId implements Serializable {
62+
private String id;
63+
}
64+
65+
@Entity
66+
public static class Bar {
67+
@EmbeddedId
68+
private BarId id;
69+
70+
@OneToOne(mappedBy = "bar")
71+
private Foo foo;
72+
}
73+
74+
@Entity
75+
public static class Foo {
76+
@EmbeddedId
77+
private FooId id;
78+
79+
@OneToOne(cascade = CascadeType.ALL)
80+
@JoinColumn(name = "bar_id")
81+
private Bar bar;
82+
}
83+
}

0 commit comments

Comments
 (0)