Hibernate @Filter can only filter table fields. What should I use to filter on entity properties, and not table columns?

I want to create a filter that can filter my queries based on Entity Objects and not Table Fields. For example, I have Entity1 that has a ManyToMany relation to Entity2

Which is

Set<Entity2>

I want to create a filter which is gonna give me a list of Entities1 where its own

Set<Entity2>

will contain only those Entity2 records as I passed there in the

parameters.filter.setParameterList("paramName",Set<Entity2>

I can’t achieve the result I need with @Filter because it’s using SQL that won’t let me compare such thing as

where (1,2) in (1,2,3)

1 Like

The best way to filter an entity is to use a query, not a @Filter or a @Where clause.

So, in your case, you are better off using a JPQL, Criteria API or native SQL query.

1 Like