diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/ComparisonOperator.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/ComparisonOperator.java index cccdad2de9..91ba8a6a83 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/ComparisonOperator.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/ComparisonOperator.java @@ -63,7 +63,7 @@ public enum ComparisonOperator { @Override public String sqlText() { - return "!="; + return "<>"; } }, NOT_DISTINCT_FROM { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseJoinedSubclassOptimizationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseJoinedSubclassOptimizationTest.java index aa4ffe4c3e..dcf1c21f49 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseJoinedSubclassOptimizationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseJoinedSubclassOptimizationTest.java @@ -189,7 +189,7 @@ public class EntityUseJoinedSubclassOptimizationTest { "when t1_1.id is not null then 6 " + "when t1_2.id is not null then 1 " + "when t1_6.id is not null then 4 " + - "end!=2", + "end<>2", sqlStatementInterceptor.getSqlQueries().get( 0 ) ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseSingleTableOptimizationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseSingleTableOptimizationTest.java index 8c7f7c7077..684135782c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseSingleTableOptimizationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseSingleTableOptimizationTest.java @@ -129,7 +129,7 @@ public class EntityUseSingleTableOptimizationTest { "t1_0.name " + "from Thing t1_0 " + "where " + - "t1_0.DTYPE!='House'", + "t1_0.DTYPE<>'House'", sqlStatementInterceptor.getSqlQueries().get( 0 ) ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseUnionSubclassOptimizationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseUnionSubclassOptimizationTest.java index 3784f1251f..e921bb0054 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseUnionSubclassOptimizationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/EntityUseUnionSubclassOptimizationTest.java @@ -145,7 +145,7 @@ public class EntityUseUnionSubclassOptimizationTest { "select id, null as nr, name, null as seats, null as architectName, null as doors, null as familyName, 4 as clazz_ from Vehicle" + ") t1_0 " + "where " + - "t1_0.clazz_!=2", + "t1_0.clazz_<>2", sqlStatementInterceptor.getSqlQueries().get( 0 ) ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/NotEqualComparisonOperatorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/NotEqualComparisonOperatorTest.java new file mode 100644 index 0000000000..e2cebc69dd --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/NotEqualComparisonOperatorTest.java @@ -0,0 +1,95 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.test.query.hql; + +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.JiraKey; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * @author Jan Schatteman + * @author Mark Russell + */ +@DomainModel( + annotatedClasses = { NotEqualComparisonOperatorTest.IntegerTextMapEntity.class } +) +@SessionFactory +public class NotEqualComparisonOperatorTest { + + @Test + @JiraKey( value = "HHH-17234") + public void testNotEqualComparison(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + var entityOne = new IntegerTextMapEntity(1, "One"); + var entityNegativeOne = new IntegerTextMapEntity(-1, "Negative One"); + session.persist(entityOne); + session.persist(entityNegativeOne); + + var tableContents = session.createQuery( + "SELECT x FROM IntegerTextMapEntity x", IntegerTextMapEntity.class ).getResultList(); + assertNotNull(tableContents); + assertEquals(2, tableContents.size()); + + var notEqualOpResults = session.createQuery( + "SELECT x FROM IntegerTextMapEntity x WHERE x.intValue <> -1", IntegerTextMapEntity.class).getResultList(); + assertNotNull(notEqualOpResults); + assertEquals(1, notEqualOpResults.size()); + } + ); + } + + @Entity( name = "IntegerTextMapEntity" ) + public static class IntegerTextMapEntity { + @Id + @GeneratedValue + private Long id; + + private Integer intValue; + + private String textValue; + + public IntegerTextMapEntity(int intValue, String textValue) { + this.intValue = intValue; + this.textValue = textValue; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Integer getIntValue() { + return intValue; + } + + public void setIntValue(Integer intValue) { + this.intValue = intValue; + } + + public String getTextValue() { + return textValue; + } + + public void setTextValue(String textValue) { + this.textValue = textValue; + } + } + +}