Skip to content

Commit d866909

Browse files
mbelladebeikov
authored andcommitted
HHH-16080 Add test for issue
1 parent 105253d commit d866909

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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.mapping.onetoone;
8+
9+
import org.hibernate.testing.orm.junit.DomainModel;
10+
import org.hibernate.testing.orm.junit.JiraKey;
11+
import org.hibernate.testing.orm.junit.SessionFactory;
12+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
13+
import org.junit.jupiter.api.BeforeAll;
14+
import org.junit.jupiter.api.Test;
15+
16+
import jakarta.persistence.Column;
17+
import jakarta.persistence.Entity;
18+
import jakarta.persistence.Id;
19+
import jakarta.persistence.JoinColumn;
20+
import jakarta.persistence.OneToOne;
21+
import jakarta.persistence.TypedQuery;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
25+
/**
26+
* @author Marco Belladelli
27+
*/
28+
@SessionFactory
29+
@DomainModel(annotatedClasses = {
30+
OneToOneIsNullQueryTest.Thing.class,
31+
OneToOneIsNullQueryTest.ThingStats.class
32+
})
33+
@JiraKey("HHH-16080")
34+
public class OneToOneIsNullQueryTest {
35+
@BeforeAll
36+
public void setUp(SessionFactoryScope scope) {
37+
scope.inTransaction( session -> {
38+
final Thing thing1 = new Thing( 1L );
39+
final ThingStats stats = new ThingStats( thing1.getPk(), 10 );
40+
thing1.setThingStats( stats );
41+
final Thing thing2 = new Thing( 2L );
42+
session.persist( thing1 );
43+
session.persist( thing2 );
44+
session.persist( stats );
45+
} );
46+
}
47+
48+
@Test
49+
public void testIsNullQuery(SessionFactoryScope scope) {
50+
scope.inTransaction( session -> {
51+
String ql = "select thing from Thing thing"
52+
+ " left join thing.thingStats thingStats "
53+
+ " where thingStats is null or thingStats.countRejected = 0";
54+
TypedQuery<Thing> q = session.createQuery( ql, Thing.class );
55+
assertThat( q.getSingleResult().getPk() ).isEqualTo( 2L );
56+
} );
57+
}
58+
59+
@Entity(name = "Thing")
60+
public static class Thing {
61+
@Id
62+
@Column(name = "thing_pk")
63+
private Long pk;
64+
65+
@OneToOne
66+
@JoinColumn(name = "thing_pk")
67+
private ThingStats thingStats;
68+
69+
public Thing() {
70+
}
71+
72+
public Thing(Long pk) {
73+
this.pk = pk;
74+
}
75+
76+
public Long getPk() {
77+
return pk;
78+
}
79+
80+
public ThingStats getThingStats() {
81+
return thingStats;
82+
}
83+
84+
public void setThingStats(ThingStats thingStats) {
85+
this.thingStats = thingStats;
86+
}
87+
}
88+
89+
@Entity(name = "ThingStats")
90+
public static class ThingStats {
91+
@Id
92+
@Column(name = "thing_fk", nullable = false)
93+
private Long thingPk;
94+
95+
private Integer countRejected;
96+
97+
public ThingStats() {
98+
}
99+
100+
public ThingStats(Long thingPk, Integer countRejected) {
101+
this.thingPk = thingPk;
102+
this.countRejected = countRejected;
103+
}
104+
105+
public Long getThingPk() {
106+
return thingPk;
107+
}
108+
109+
public Integer getCountRejected() {
110+
return countRejected;
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)