Skip to content

Commit 8fa64ba

Browse files
gtoisonmbellade
authored andcommitted
HHH-18885 test reproducing the issue
1 parent ea78f09 commit 8fa64ba

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.extralazy;
6+
7+
import java.time.LocalDate;
8+
import java.util.TreeMap;
9+
import java.util.SortedMap;
10+
11+
12+
import org.hibernate.annotations.LazyCollection;
13+
import org.hibernate.annotations.LazyCollectionOption;
14+
import org.hibernate.annotations.SortNatural;
15+
16+
import org.hibernate.testing.orm.junit.DomainModel;
17+
import org.hibernate.testing.orm.junit.Jira;
18+
import org.hibernate.testing.orm.junit.SessionFactory;
19+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
20+
import org.junit.jupiter.api.Test;
21+
22+
import jakarta.persistence.Entity;
23+
import jakarta.persistence.FetchType;
24+
import jakarta.persistence.Id;
25+
import jakarta.persistence.ManyToOne;
26+
import jakarta.persistence.OneToMany;
27+
import jakarta.persistence.Column;
28+
import jakarta.persistence.JoinColumn;
29+
import jakarta.persistence.MapKeyColumn;
30+
31+
32+
/**
33+
* @author Guillaume Toison
34+
*/
35+
@Jira( "https://hibernate.atlassian.net/browse/HHH-18885" )
36+
@DomainModel( annotatedClasses = {
37+
ExtraLazyMapQueuedPersistTest.Person.class,
38+
ExtraLazyMapQueuedPersistTest.Event.class,
39+
} )
40+
@SessionFactory( useCollectingStatementInspector = true )
41+
public class ExtraLazyMapQueuedPersistTest {
42+
@Test
43+
public void testQueuedPersistOperation(SessionFactoryScope scope) {
44+
scope.inTransaction( session -> {
45+
final Person person = new Person( 1L );
46+
47+
session.persist ( person );
48+
} );
49+
50+
scope.inTransaction( session -> {
51+
final Person person = session.find( Person.class, 1L );
52+
53+
LocalDate date = LocalDate.of( 2024, 1, 1 );
54+
Event event = new Event( 1L, person, date );
55+
56+
person.getEvents().put( date, event );
57+
} );
58+
}
59+
60+
@Entity( name = "Person" )
61+
public static class Person {
62+
@Id
63+
private Long id;
64+
65+
@OneToMany(mappedBy = "person")
66+
@MapKeyColumn(name = "date_col")
67+
@SortNatural
68+
@LazyCollection(LazyCollectionOption.EXTRA)
69+
private SortedMap<LocalDate, Event> events = new TreeMap<>();
70+
71+
public Person() {
72+
}
73+
74+
public Person(Long id) {
75+
this.id = id;
76+
}
77+
78+
public SortedMap<LocalDate, Event> getEvents() {
79+
return events;
80+
}
81+
82+
public void setEvents(SortedMap<LocalDate, Event> events) {
83+
this.events = events;
84+
}
85+
}
86+
87+
@Entity( name = "Event" )
88+
public static class Event {
89+
@Id
90+
private Long id;
91+
92+
@ManyToOne(fetch = FetchType.LAZY)
93+
@JoinColumn(name = "person_id")
94+
private Person person;
95+
96+
@Column( name="date_col" )
97+
private LocalDate date;
98+
99+
public Event() {
100+
}
101+
102+
public Event(Long id, Person person, LocalDate date) {
103+
this.id = id;
104+
this.person = person;
105+
this.date = date;
106+
}
107+
108+
public Long getId() {
109+
return id;
110+
}
111+
112+
public void setId(Long id) {
113+
this.id = id;
114+
}
115+
116+
public Person getPerson() {
117+
return person;
118+
}
119+
120+
public void setPerson(Person person) {
121+
this.person = person;
122+
}
123+
124+
public LocalDate getDate() {
125+
return date;
126+
}
127+
128+
public void setDate(LocalDate date) {
129+
this.date = date;
130+
}
131+
}
132+
}

0 commit comments

Comments
 (0)