File tree 4 files changed +33
-4
lines changed
hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idmanytoone
4 files changed +33
-4
lines changed Original file line number Diff line number Diff line change 5
5
package org .hibernate .orm .test .annotations .idmanytoone ;
6
6
7
7
import java .io .Serializable ;
8
+ import java .util .HashSet ;
8
9
import java .util .Set ;
10
+
11
+ import jakarta .persistence .CascadeType ;
9
12
import jakarta .persistence .Entity ;
10
13
import jakarta .persistence .GeneratedValue ;
11
14
import jakarta .persistence .Id ;
@@ -25,8 +28,8 @@ public class Course implements Serializable {
25
28
26
29
private String name ;
27
30
28
- @ OneToMany (mappedBy = "course" )
29
- private Set <CourseStudent > students ;
31
+ @ OneToMany (mappedBy = "course" , cascade = CascadeType . ALL )
32
+ private Set <CourseStudent > students = new HashSet <>() ;
30
33
31
34
public Course () {
32
35
}
Original file line number Diff line number Diff line change 12
12
import jakarta .persistence .JoinColumn ;
13
13
import jakarta .persistence .ManyToOne ;
14
14
import jakarta .persistence .Table ;
15
+ import org .hibernate .annotations .processing .Exclude ;
15
16
16
17
/**
17
18
* @author Alex Kalashnikov
18
19
*/
19
20
@ Entity
20
21
@ Table (name = "idmanytoone_course_student" )
22
+ @ Exclude // Avoid generating an IdClass through the annotation processor. See https://hibernate.atlassian.net/browse/HHH-18829
21
23
public class CourseStudent implements Serializable {
22
24
23
25
@ Id
Original file line number Diff line number Diff line change 14
14
import org .hibernate .boot .model .naming .ImplicitNamingStrategyJpaCompliantImpl ;
15
15
import org .hibernate .cfg .Configuration ;
16
16
17
+ import org .hibernate .testing .orm .junit .Jira ;
17
18
import org .hibernate .testing .orm .junit .JiraKey ;
18
19
import org .hibernate .testing .junit4 .BaseCoreFunctionalTestCase ;
19
20
import org .junit .Test ;
@@ -78,6 +79,26 @@ public void testCriteriaRestrictionOnIdManyToOne() {
78
79
} );
79
80
}
80
81
82
+ @ Test
83
+ @ Jira ("https://hibernate.atlassian.net/browse/HHH-11026" )
84
+ public void testMerge () {
85
+ inTransaction ( s -> {
86
+ Student student = new Student ();
87
+ student .setName ( "s1" );
88
+ Course course = new Course ();
89
+ course .setName ( "c1" );
90
+ s .persist ( student );
91
+ s .persist ( course );
92
+
93
+ CourseStudent courseStudent = new CourseStudent ();
94
+ courseStudent .setStudent ( student );
95
+ courseStudent .setCourse ( course );
96
+ student .getCourses ().add ( courseStudent );
97
+ course .getStudents ().add ( courseStudent );
98
+ s .merge ( student );
99
+ } );
100
+ }
101
+
81
102
@ Override
82
103
protected Class [] getAnnotatedClasses () {
83
104
return new Class [] {
Original file line number Diff line number Diff line change 5
5
package org .hibernate .orm .test .annotations .idmanytoone ;
6
6
7
7
import java .io .Serializable ;
8
+ import java .util .HashSet ;
8
9
import java .util .Set ;
10
+
11
+ import jakarta .persistence .CascadeType ;
9
12
import jakarta .persistence .Entity ;
10
13
import jakarta .persistence .GeneratedValue ;
11
14
import jakarta .persistence .Id ;
@@ -25,8 +28,8 @@ public class Student implements Serializable {
25
28
26
29
private String name ;
27
30
28
- @ OneToMany (mappedBy = "student" )
29
- private Set <CourseStudent > courses ;
31
+ @ OneToMany (mappedBy = "student" , cascade = CascadeType . ALL )
32
+ private Set <CourseStudent > courses = new HashSet <>() ;
30
33
31
34
public Student () {
32
35
}
You can’t perform that action at this time.
0 commit comments