Skip to content

Commit 318a543

Browse files
jrenaatbeikov
authored andcommitted
HHH-17234 - Add test case and fix for issue (change the "!=" not equal operator to "<>")
Signed-off-by: Jan Schatteman <[email protected]> (cherry picked from commit e92cbac)
1 parent 5e17e12 commit 318a543

File tree

5 files changed

+99
-4
lines changed

5 files changed

+99
-4
lines changed

hibernate-core/src/main/java/org/hibernate/query/sqm/ComparisonOperator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public ComparisonOperator sharper() {
6363

6464
@Override
6565
public String sqlText() {
66-
return "!=";
66+
return "<>";
6767
}
6868
},
6969
NOT_DISTINCT_FROM {

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseJoinedSubclassOptimizationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void testNotEqTypeRestriction(SessionFactoryScope scope) {
189189
"when t1_1.id is not null then 6 " +
190190
"when t1_2.id is not null then 1 " +
191191
"when t1_6.id is not null then 4 " +
192-
"end!=2",
192+
"end<>2",
193193
sqlStatementInterceptor.getSqlQueries().get( 0 )
194194
);
195195
}

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseSingleTableOptimizationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void testNotEqTypeRestriction(SessionFactoryScope scope) {
129129
"t1_0.name " +
130130
"from Thing t1_0 " +
131131
"where " +
132-
"t1_0.DTYPE!='House'",
132+
"t1_0.DTYPE<>'House'",
133133
sqlStatementInterceptor.getSqlQueries().get( 0 )
134134
);
135135
}

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseUnionSubclassOptimizationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void testNotEqTypeRestriction(SessionFactoryScope scope) {
145145
"select id, null as nr, name, null as seats, null as architectName, null as doors, null as familyName, 4 as clazz_ from Vehicle" +
146146
") t1_0 " +
147147
"where " +
148-
"t1_0.clazz_!=2",
148+
"t1_0.clazz_<>2",
149149
sqlStatementInterceptor.getSqlQueries().get( 0 )
150150
);
151151
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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.query.hql;
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.Test;
14+
15+
import jakarta.persistence.Entity;
16+
import jakarta.persistence.GeneratedValue;
17+
import jakarta.persistence.Id;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
22+
/**
23+
* @author Jan Schatteman
24+
* @author Mark Russell
25+
*/
26+
@DomainModel(
27+
annotatedClasses = { NotEqualComparisonOperatorTest.IntegerTextMapEntity.class }
28+
)
29+
@SessionFactory
30+
public class NotEqualComparisonOperatorTest {
31+
32+
@Test
33+
@JiraKey( value = "HHH-17234")
34+
public void testNotEqualComparison(SessionFactoryScope scope) {
35+
scope.inTransaction(
36+
session -> {
37+
var entityOne = new IntegerTextMapEntity(1, "One");
38+
var entityNegativeOne = new IntegerTextMapEntity(-1, "Negative One");
39+
session.persist(entityOne);
40+
session.persist(entityNegativeOne);
41+
42+
var tableContents = session.createQuery(
43+
"SELECT x FROM IntegerTextMapEntity x", IntegerTextMapEntity.class ).getResultList();
44+
assertNotNull(tableContents);
45+
assertEquals(2, tableContents.size());
46+
47+
var notEqualOpResults = session.createQuery(
48+
"SELECT x FROM IntegerTextMapEntity x WHERE x.intValue <> -1", IntegerTextMapEntity.class).getResultList();
49+
assertNotNull(notEqualOpResults);
50+
assertEquals(1, notEqualOpResults.size());
51+
}
52+
);
53+
}
54+
55+
@Entity( name = "IntegerTextMapEntity" )
56+
public static class IntegerTextMapEntity {
57+
@Id
58+
@GeneratedValue
59+
private Long id;
60+
61+
private Integer intValue;
62+
63+
private String textValue;
64+
65+
public IntegerTextMapEntity(int intValue, String textValue) {
66+
this.intValue = intValue;
67+
this.textValue = textValue;
68+
}
69+
70+
public Long getId() {
71+
return id;
72+
}
73+
74+
public void setId(Long id) {
75+
this.id = id;
76+
}
77+
78+
public Integer getIntValue() {
79+
return intValue;
80+
}
81+
82+
public void setIntValue(Integer intValue) {
83+
this.intValue = intValue;
84+
}
85+
86+
public String getTextValue() {
87+
return textValue;
88+
}
89+
90+
public void setTextValue(String textValue) {
91+
this.textValue = textValue;
92+
}
93+
}
94+
95+
}

0 commit comments

Comments
 (0)