Query By Proxy (QBP)

A java criteria api where path expressions are constructed by invoking methods on a proxy for an entity-class (supports both JPA and Hibernate).

State: Beta

General Advantages:

  • Strongly typed
  • Covers the entire JPA 1.0 specification

Advantages over JPA 2.0 criteria api:

  • No code generation required
  • Terse syntax
  • Does not require vendor implementation (can be used very soon anywhere jpa is implemented)
  • Technique is not jpa specific (can be used to create a comparator)

Usage:

ProxyQuery<Customer> query = queryFactory.createQuery(Customer.class);
Customer customer = query.getRootProxy();

query.andWhere(customer.getFirstName()).equalTo("John");

List<Customer> results = query.find();

--produces the following hql/jpql: 
      SELECT a FROM Customer a WHERE a.firstName = 'John'
						

More Information:

Query By Proxy Wiki