Ebean 2.6.0 API

Ebean Object Relational Mapping (start at Ebean or EbeanServer).


Public API
com.avaje.ebean Core API (see Ebean and EbeanServer).
com.avaje.ebean.annotation Extra deployment annotations
com.avaje.ebean.bean Enhanced beans API and Support objects
com.avaje.ebean.cache Server Cache Service
com.avaje.ebean.common Common non-public interfaces and implementation.
com.avaje.ebean.config Configuration settings for EbeanServer construction
com.avaje.ebean.config.dbplatform Database platform specific support
com.avaje.ebean.config.ldap LDAP configuration objects.
com.avaje.ebean.event Persist and Query Event Controllers and Listeners
com.avaje.ebean.meta Entity Beans for getting "Meta" data from Ebean
com.avaje.ebean.text Utility objects for CSV, JSON and XML processing.
com.avaje.ebean.text.csv CSV processing objects.
com.avaje.ebean.text.json JSON formatting and parsing objects (See JsonContext).
com.avaje.ebean.validation Annotations for validating entity beans.
com.avaje.ebean.validation.factory Factories to create validators.


Ebean Object Relational Mapping (start at Ebean or EbeanServer).


Provides the main API for fetching and persisting beans with Ebean.

For a full description of the query language refer to Query.


EXAMPLE 1: Simple fetch

// fetch order 10
Order order = Ebean.find(Order.class, 10);

EXAMPLE 2: Fetch an Object with associations

// fetch Customer 7 including their billing and shipping addresses
Customer customer = Ebean.find(Customer.class)
Address billAddr = customer.getBillingAddress();
Address shipAddr = customer.getShippingAddress();

EXAMPLE 3: Fetch a list of Objects with associations

// Note: This example shows a "Partial Object".
//       For the product objects associated with the 
//       order details only the product id and name is
//       fetched (the product objects are partially populated).
// fetch orders for customer.id = 2
List<Order> orderList = Ebean.find(Order.class);

// Note: Only the product id and name is fetched for the
//       product details. This is referred to as a 
//       "Partial Object" (one that is partially populated).  

// code that traverses the object graph...

Order order = orderList.get(0);
Customer customer = order.getCustomer();        
Address shipAddr = customer.getShippingAddress();

List<OrderDetail> details = order.getDetails();
OrderDetail detail = details.get(0);
Product product = detail.getProduct();
String productName = product.getName();

EXAMPLE 4: Create and save an Order

// get a Customer reference so we don't hit the database
Customer custRef = Ebean.getReference(Customer.class, 7);

// create a new Order object
Order newOrder = new Order();

ArrayList orderLines = new ArrayList();

// add a line to the order
Product prodRef = Ebean.getReference(Product.class, 41);
OrderLine line = new OrderLine();

// save the order and its lines in a single transaction
// NB: assumes CascadeType.PERSIST is set on the order lines association

EXAMPLE 5: Use another database

// Get access to the Human Resources EbeanServer/Database
EbeanServer hrServer = Ebean.getServer("HR");
// fetch contact 3 from the HR database
Contact contact = hrServer.find(Contact.class, 3);
// save the contact back to the HR database

Copyright © 2010. All Rights Reserved.