|
| 1 | +package org.hibernate.orm.test.filter; |
| 2 | + |
| 3 | +import org.hibernate.annotations.Filter; |
| 4 | +import org.hibernate.annotations.FilterDef; |
| 5 | +import org.hibernate.annotations.ParamDef; |
| 6 | + |
| 7 | +import org.hibernate.testing.orm.junit.DialectFeatureChecks; |
| 8 | +import org.hibernate.testing.orm.junit.DomainModel; |
| 9 | +import org.hibernate.testing.orm.junit.JiraKey; |
| 10 | +import org.hibernate.testing.orm.junit.RequiresDialectFeature; |
| 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 | + |
| 20 | +@DomainModel( |
| 21 | + annotatedClasses = { |
| 22 | + FilterWithILikeTest.TestEntity.class |
| 23 | + } |
| 24 | +) |
| 25 | +@SessionFactory |
| 26 | +@JiraKey("HHH-16464") |
| 27 | +@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsCaseInsensitiveLike.class) |
| 28 | +public class FilterWithILikeTest { |
| 29 | + |
| 30 | + @BeforeAll |
| 31 | + public void setUp(SessionFactoryScope scope) { |
| 32 | + scope.inTransaction( |
| 33 | + session -> { |
| 34 | + TestEntity filtered = new TestEntity( 1, "filtered" ); |
| 35 | + session.persist( filtered ); |
| 36 | + |
| 37 | + TestEntity notFiltered = new TestEntity( 2, "not_filtered" ); |
| 38 | + session.persist( notFiltered ); |
| 39 | + } |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testQuery(SessionFactoryScope scope) { |
| 45 | + |
| 46 | + scope.inTransaction( |
| 47 | + session -> { |
| 48 | + session.enableFilter( "nameFilter" ).setParameter( "name", "not_filtered" ); |
| 49 | + session.createQuery( "from TestEntity " ).list(); |
| 50 | + } |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + @FilterDef(name = "nameFilter", parameters = { |
| 55 | + @ParamDef(name = "name", type = String.class) |
| 56 | + }) |
| 57 | + @Filter(name = "nameFilter", condition = "NAME ilike :name") |
| 58 | + @Entity(name = "TestEntity") |
| 59 | + public static class TestEntity { |
| 60 | + @Id |
| 61 | + private Integer id; |
| 62 | + |
| 63 | + @Column(name = "NAME") |
| 64 | + private String name; |
| 65 | + |
| 66 | + public TestEntity() { |
| 67 | + } |
| 68 | + |
| 69 | + public TestEntity(Integer id, String name) { |
| 70 | + this.id = id; |
| 71 | + this.name = name; |
| 72 | + } |
| 73 | + |
| 74 | + public Integer getId() { |
| 75 | + return id; |
| 76 | + } |
| 77 | + |
| 78 | + public String getName() { |
| 79 | + return name; |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments