# Session.createFilter is deprecated in Hibernate ORM 5.3. Is there any alternative?

**URL:** <https://discourse.hibernate.org/t/session-createfilter-is-deprecated-in-hibernate-orm-5-3-is-there-any-alternative/940>\
**Category:** Hibernate ORM\
**Created:** [June 19, 2018, 5:03pm UTC](https://discourse.hibernate.org/t/session-createfilter-is-deprecated-in-hibernate-orm-5-3-is-there-any-alternative/940 "2018-06-19T17:03:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![caristu](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@caristu](https://discourse.hibernate.org/u/caristu)\
**Post date:** [June 19, 2018, 5:03pm UTC](https://discourse.hibernate.org/t/session-createfilter-is-deprecated-in-hibernate-orm-5-3-is-there-any-alternative/940/1 "2018-06-19T17:03:16Z")

</div>

Hello,

starting from Hibernate 5.3 Session.createFilter(Object, String) has been deprecated[1] with no real replacement.

What do you think that it could the best approach to take if I would like to filter a given collection and replace the usage of that method?

Thank you in advance.

[1] [https://docs.jboss.org/hibernate/orm/5.3/javadocs/](https://docs.jboss.org/hibernate/orm/5.3/javadocs/)

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [June 19, 2018, 5:46pm UTC](https://discourse.hibernate.org/t/session-createfilter-is-deprecated-in-hibernate-orm-5-3-is-there-any-alternative/940/2 "2018-06-19T17:46:16Z")

</div>

You can use the `@Filter` annotation on collections [as explained in the User Guide](http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#mapping-column-filter).

Or you can use the [`@Where` annotation](http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#mapping-where-example) if the filtering is not dynamic.

---

<div class="post-metadata">

**Author:** ![caristu](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@caristu](https://discourse.hibernate.org/u/caristu)\
**Post date:** [June 20, 2018, 11:02am UTC](https://discourse.hibernate.org/t/session-createfilter-is-deprecated-in-hibernate-orm-5-3-is-there-any-alternative/940/3 "2018-06-20T11:02:56Z")

</div>

Hello,

thanks for the response. And what if I’m still not building the mapping with JPA annotations? In my case I’m still building the mapping with an .hbm file. Then at one point in my code I’m doing the following:

session.createFilter(collection,“where language = :language”).setParameter(“language”, language).list();

Is there any workaround for this? Or the only way is by replacing it with a Query?

Thanks again.

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [June 20, 2018, 11:15am UTC](https://discourse.hibernate.org/t/session-createfilter-is-deprecated-in-hibernate-orm-5-3-is-there-any-alternative/940/4 "2018-06-20T11:15:15Z")

</div>

Those annotations have an equivalent in HBM mappings. However, HBM mappings are also deprecated. You might want to migrate to annotations, which are better supported anyway.

Other workaround is to write a Query. You can use Criteria API if the query needs to be build dynamically.

---

<div class="post-metadata">

**Author:** ![caristu](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@caristu](https://discourse.hibernate.org/u/caristu)\
**Post date:** [June 20, 2018, 5:09pm UTC](https://discourse.hibernate.org/t/session-createfilter-is-deprecated-in-hibernate-orm-5-3-is-there-any-alternative/940/5 "2018-06-20T17:09:19Z")

</div>

Ok, understood! Thank you!

---

<div class="post-metadata">

**Author:** ![Fernando\_Salgueiro](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/fernando_salgueiro/32/1358_2.png) [@Fernando\_Salgueiro](https://discourse.hibernate.org/u/Fernando_Salgueiro)\
**Post date:** [February 1, 2021, 1:47pm UTC](https://discourse.hibernate.org/t/session-createfilter-is-deprecated-in-hibernate-orm-5-3-is-there-any-alternative/940/6 "2021-02-01T13:47:47Z")

</div>

Hi Vlad,

In my project, to replace all createFilter methods , it can be complex even with CriteriaQuery.  
Do you know examples, with Criteria?

Following the example below , how i would apply Criteria in easy way, if my collection is  
ListDefinition list = getListDefinition(listId); instead a table ?

public Collection getListColumnsOrderedByName (Long listId)  
{

```
    ListDefinition list = getListDefinition(listId);
    
    Collection OrderedColumns = wlmDaoHelper.getListDefinitionDao().filter(list.getListColumns(), "order by this.columnName");

```

// Collection OrderedColumns = wlmDaoHelper.getCurrentTransactionalHibernateSession().filter(list.getListColumns(),  
// “order by this.columnName”);

```
    return OrderedColumns;
}
```
