Filtering JPAContainer

Normally, a JPAContainer contains all instances of a particular entity type in the persistence context. Hence, it is equivalent to a database table or query. Just like with database queries, you often want to narrow the results down. JPAContainer implements the Filterable interface in Vaadin containers, described in “Filterable Containers”. All filtering is done at the database level with queries, not in the container.

For example, let us filter all the people older than 117:

  1. Filter filter = new Compare.Greater("age", 117);
  2. persons.addContainerFilter(filter);

See the on-line example.

This would create a JPQL query somewhat as follows:

  1. SELECT id FROM Person WHERE (AGE > 117)

See the on-line example.

The filtering implementation uses the JPA 2.0 Criteria API transparently. As the filtering is done at the database-level, custom filters that use the Filterable API do not work.

When using Hibernate, note that it does not support implicit joins. See “Joins in Hibernate vs EclipseLink” for more details.