Posted By:
Bozidar_Dangubic
Posted On:
Sunday, November 11, 2001 11:40 AM
well, you may need to elaborate on "lazy loading" the container uses bean callbacks when certain client operations are peformed. the container will call ejbLoad() to load the data if client performs findByPrimaryKey because it knows what to load. the container will not call ejbLoad() if client invokes findBySomethingElse which returns a Collection as a result. you can say that container performs lazy loading for you automatically when search results are Collection versus single result (such as the case with findByPrimaryKey). if you want to implement lazy loading even for findByPrimaryKey call, leave ejbLoad() blank. create a method which loads the data for you and call at the top of each business method. therefore, nothing will get loaded until the client actually needs it. so simple example: lets say you have two business methods in your bean, getStockPrice(String company) and setStockPrice(String company). here is what you can do.
public void ejbLoad()
{
// ... empty for lazy loading
}
private void loadData()
{
if(data_not_loaded_already)
{
// ... go to DB and get the data
}
}
public double getStockPrice(String company)
{
loadData();
return stock_price_of_company;
}
public void setStockPrice(String company)
{
loadData();
set_stock_price_of_company;
}