HHH-17234 - Add test case and fix for issue (change the "!=" not equal operator to "<>")

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2023-09-22 21:50:42 +02:00 committed by Jan Schatteman
parent e7ad69d09c
commit e92cbac8dc
5 changed files with 99 additions and 4 deletions

View File

@ -63,7 +63,7 @@ public enum ComparisonOperator {
@Override @Override
public String sqlText() { public String sqlText() {
return "!="; return "<>";
} }
}, },
NOT_DISTINCT_FROM { NOT_DISTINCT_FROM {

View File

@ -189,7 +189,7 @@ public class EntityUseJoinedSubclassOptimizationTest {
"when t1_1.id is not null then 6 " + "when t1_1.id is not null then 6 " +
"when t1_2.id is not null then 1 " + "when t1_2.id is not null then 1 " +
"when t1_6.id is not null then 4 " + "when t1_6.id is not null then 4 " +
"end!=2", "end<>2",
sqlStatementInterceptor.getSqlQueries().get( 0 ) sqlStatementInterceptor.getSqlQueries().get( 0 )
); );
} }

View File

@ -129,7 +129,7 @@ public class EntityUseSingleTableOptimizationTest {
"t1_0.name " + "t1_0.name " +
"from Thing t1_0 " + "from Thing t1_0 " +
"where " + "where " +
"t1_0.DTYPE!='House'", "t1_0.DTYPE<>'House'",
sqlStatementInterceptor.getSqlQueries().get( 0 ) sqlStatementInterceptor.getSqlQueries().get( 0 )
); );
} }

View File

@ -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" + "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 " + ") t1_0 " +
"where " + "where " +
"t1_0.clazz_!=2", "t1_0.clazz_<>2",
sqlStatementInterceptor.getSqlQueries().get( 0 ) sqlStatementInterceptor.getSqlQueries().get( 0 )
); );
} }

View File

@ -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;
}
}
}