Sets the table alias to use on the base table.

List<Customer> customers =
    new QCustomer()
select, cust.inactive,, cust.registered, ...
from customer cust
where lower( like ? escape'|' ; --bind(rob%)

The typically use of alias is when used as a subquery.

Query<Order> subQuery = new QOrder()
  .select("id").where().raw("sub.customer_id =")

List<Customer> customers = new QCustomer()
select, main.inactive,, main.registered, ...
from customer main
where  exists (select from orders sub where sub.customer_id =


Used to fetch a @Draftable entities from their draft table(s) rather than the published tables.

Document documentDraft =
  new QDocument()

As of timestamp

For entities with @History fetch the entities AS OF the given timestamp.

Timestamp timeInPast = ...;

List<Customer> customers
  = new QCustomer()


Turn on or off automatic query tuning.

List<|Customer> customers = new QCustomer() .setAutoTune(true) // automatically tune the query .status.equalTo(Status.NEW) .findList();


A hint which for JDBC translates to the Statement.fetchSize().

Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for ResultSet.


Disables any lazy loading that would otherwise occur. Instead unloaded properties would return null.


Disable read auditing for this query. Refer to Read Auditing.

This is intended to be used when the query is not a user initiated query and instead part of the internal processing in an application to load a cache or document store etc. In these cases we don't want the query to be part of read auditing.


Make the query use sql distinct.

List<String> lastNames =
  new QContact()
int count =
  new QCustomer()
select count(distinct t0.anniversary) from customer t0 where t0.status = ?
// partially loaded beans without Id properties
// ... not persistable, no lazy loading etc

List<Customer> beans =
  new QContact()
      .select("lastName, dateOfBirth")


Execute the query with FOR UPDATE that will hold a lock on the rows fetched.

try (Transaction txn = database.beginTransaction()) {

  Customer customer =
    new QContact()

  customer.setName("a better name");;



Set to true to include soft deleted rows. Refer to Soft Delete.


Set this to tune the lazy loading batch size which by default is set to 10.


Generally queries run with transaction scoped persistence context. With this we can set to QUERY the object graph built will be fresh data from the database ignoring any existing bean that is in the [transaction] persistence context.

try (Transaction txn = database.beginTransaction()) {

  // when customer is loaded it then is referenced in the
  // transaction scoped persistence context (aka L1 cache)
  Customer loaded = Customer.find.byId(42)

  // fetch this same customer but we want to ignore the L1 cache
  // such that we get a "fresh" version of its data

  Customer customer =
    new QCustomer()
      .setUseCache(false)                        // ignore L2 cache
      .setPersistenceContextScope(QUERY)         // ignore L1 cache




Query returns beans that are deemed to be READ ONLY and calling setter methods will throw an exception.