Partial Objects

Partial objects are where part of the entity bean is populated. This is an important feature for performance and also design reasons.

example

Queries - Partial Objects covers how to query partial objects.

LAZY LOADING

A Partial Object will lazy load the rest of the data on demand when you get or set a property it does not have.


// find order 12
// ... fetching the order id, orderDate and version property
// .... nb: the Id and version property are always fetched

Order order = Ebean.find(Order.class)
		.select("orderDate")
		.where().idEq(12)
		.findUnique();

// shipDate is not in the partially populated order
// ... so it will lazy load all the missing properties
Date shipDate = order.getShipDate();

// similarly if we where to set the shipDate 
// ... that would also trigger a lazy load
order.setShipDate(new Date());

Lazy loading occurs automatically when you set or get a property that the partially populated bean does not have.

SAVING A PARTIAL OBJECT

You can save or delete a Partial Object.


// find customer 1
// ... just fetch the customer id, name and version property
Customer customer = Ebean.find(Customer.class)
		.select("name")
		.where().idEq(1)
		.findUnique();

customer.setName("CoolName");

Ebean.save(customer);

The query generates the following SQL...

<sql summary='[app.data.test.Customer]'>
select c.id, c.name 
from or_customer c 
where c.id = ?  
</sql>

... and in the transaction logs we can find the update dml and bind values.

... update or_customer set name=?, updtime=? where id=? and name=? 
... Binding Update [or_customer]  set[name=CoolName, updtime=2008-11-19 10:58:08.598, ] where[id=1, name=Ford, ] 
... Updated [app.data.test.Customer] [1] 
Introduction User Guide (pdf) Install/Configure Public JavaDoc Whitepapers
General Database Specific Byte Code Deployment Annotations Features
Top Bugs Top Enhancements
woResponse