When to use access beans or data beans in Websphere Commerce?

Michael picture Michael · Nov 15, 2012 · Viewed 8.5k times · Source

When is it appropriate to use a data bean or access bean in Websphere? Apologies if I'm asking basic questions, I'm new to Websphere.

In my case, I'm trying to find a list of catalogues by product. Initially I've been using the access bean. This works, but it sometimes returns very large result sets / seems very memory intensive.

CatalogEntryDescriptionAccessBean cedabp = new CatalogEntryDescriptionAccessBean();
Enumeration cde = cedabp.findByCatalogEntry(productCatIdLong);

The data bean provides the same method:

CatalogEntryDescriptionDataBean cedabp = new CatalogEntryDescriptionDataBean();
Enumeration cde = cedabp.findByCatalogEntry(productCatIdLong);

Why would I use one bean over the other? Is one more appropriate for reading or writing data? Is the data provided by one cached / more current than the other?

Update:

I found that the two classes have the following relationship:

CatalogEntryDescriptionAccessBean
|_ CachedCatalogEntryDescriptionAccessBean
  |_ CompactCatalogEntryDescriptionAccessBean
    |_ CatalogEntryDescriptionDataBeanBase
      |_ CatalogEntryDescriptionDataBean

So the Data Bean inherits from the Access Bean, hence why it contains the same visible methods.

Interestingly, IBM's documentation states:

Access beans provide ... caching of the home object, and reduced call traffic to the enterprise bean. Using access beans has additional advantages:

At run time the access bean caches the enterprise bean home object because look ups to the home object are expensive, in terms of time and resource usage. The access bean implements a copyHelper object that reduces the number of calls to the enterprise bean when commands get and set enterprise bean attributes. Only a single call to the enterprise bean is required when reading or writing multiple enterprise bean attributes.

At the moment, I'm confused about what purpose the Data Bean serves, if the Access Bean is using CMP to reduce calls to the Entity Bean?

I've found some more documentation that states:

A data bean is a Java bean that is used in JSP pages to retrieve information from the enterprise bean. A simple data bean extends its corresponding access bean and implements the SmartDataBean interface. By extending an access bean, the data bean provides a simple representation (indirectly) of an entity bean: it encapsulates the properties that can be retrieved from or set within the entity bean.

Answer

Michael picture Michael · Dec 12, 2012

DataBean's implement more caching than a AccessBean, so potentially reduce calls to the database.

DataBean's are appropriate for use in the JSP pages that make up the site / web application as the number of instances is likely to be low and it should help control the number of transactions hitting the database.

AccessBean's are much less memory intensive, so can be more appropriate to looping processes etc.

You'd normally expect to find AccessBean's used in back-end WebSphere commands and reports etc.