HHH-16454 Add test for issue

This commit is contained in:
Andrea Boriero 2024-02-07 12:01:28 +01:00 committed by Marco Belladelli
parent 6138c76c72
commit a2d3315067
No known key found for this signature in database
GPG Key ID: D1D0C3030AE3AA35
2 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,82 @@
package org.hibernate.orm.test.filter;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.ParamDef;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
@DomainModel(
annotatedClasses = {
FilterWithILikeTest.TestEntity.class
}
)
@SessionFactory
@JiraKey("HHH-16464")
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsCaseInsensitiveLike.class)
public class FilterWithILikeTest {
@BeforeAll
public void setUp(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
TestEntity filtered = new TestEntity( 1, "filtered" );
session.persist( filtered );
TestEntity notFiltered = new TestEntity( 2, "not_filtered" );
session.persist( notFiltered );
}
);
}
@Test
public void testQuery(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.enableFilter( "nameFilter" ).setParameter( "name", "not_filtered" );
session.createQuery( "from TestEntity " ).list();
}
);
}
@FilterDef(name = "nameFilter", parameters = {
@ParamDef(name = "name", type = String.class)
})
@Filter(name = "nameFilter", condition = "NAME ilike :name")
@Entity(name = "TestEntity")
public static class TestEntity {
@Id
private Integer id;
@Column(name = "NAME")
private String name;
public TestEntity() {
}
public TestEntity(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public String getName() {
return name;
}
}
}

View File

@ -678,4 +678,11 @@ abstract public class DialectFeatureChecks {
return dialect.getPreferredSqlTypeCodeForArray() != SqlTypes.VARBINARY;
}
}
public static class SupportsCaseInsensitiveLike implements DialectFeatureCheck {
@Override
public boolean apply(Dialect dialect) {
return dialect.supportsCaseInsensitiveLike();
}
}
}