Loading and Storing an Entity

Other than executing business methods, most of the work done by your entity bean involves keeping its state in synch with its corresponding data in the database. This work is done by your ejbLoad and ejbStore methods.

Implementing ejbLoad

The container calls ejbLoad when an entity is activated and needs to guarantee that its state in memory matches what’s in the database. Listing 6.7 shows the ejbLoad method for EnglishAuctionBean.

Listing 6.7. ejbLoad–A BMP ejbLoad Method Retrieves Data from the Database
 package com.que.ejb20.auction.model; ... public class EnglishAuctionBean extends AbstractEntity implements EntityBean { ... public void ejbLoad() { Connection con = null; PreparedStatement stmt = null; ResultSet ...

Get Special Edition Using Enterprise JavaBeans™ 2.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.