Queries in Ebean

Basics

example
// find an order by its id
Order order = Ebean.find(Order.class, 12);
example
// find all the orders
List<Order> list = Ebean.find(Order.class).findList();
example

... with a where clause

// find all the orders shipped since a week ago
List<Order> list = Ebean.find(Order.class)
        .where()
          .eq("status", Order.Status.SHIPPED)
          .gt("shipDate", lastWeek)
        .findList();

eq = equals
gt = greater than

example

...using the query language

// using the query language
String query = "find order where status.code=:status and shipDate > :shipped";

List<Order> list = Ebean.find(Order.class)
        .setQuery(query)
        .setParameter("status", Order.Status.SHIPPED)
        .setParameter("shipped", lastWeek)
        .findList();

Here we are using the query language with named parameters to perform the same query

<sql summary='[app.data.test.Order] autoFetchTuned[false]'>
select o.id, o.order_date, o.ship_date, o.cretime, o.updtime, o.status_code, o.customer_id 
from or_order o 
where o.status_code = ? and o.ship_date > ?
</sql>
Introduction User Guide (pdf) Install/Configure Public JavaDoc Whitepapers
General Database Specific Byte Code Deployment Annotations Features
Top Bugs Top Enhancements
woResponse