Go Premium for a chance to win a PS4. Enter to Win


How can I refresh the entitybean?

Posted on 2001-07-02
Medium Priority
Last Modified: 2013-11-24
Hi friends,

  In one entitybean, there is a private method refresh(AgentPK pk), here
we load the bean instance with data from back store. This method is called
in ejbLoad(). In refresh method, we first check isModified() for the flag,
if it is true, we do the refresh, if false we do not refresh. At the end of
refresh method, however, the modification flay was set to false :
setModified(false) so that this bean will not be refreshed as long as the
server is up.

  The code is like this:

    public void ejbLoad() throws RemoteException
    logDebug("ejbLoad: " + context,100);
    try {
      // call the refresh method with the current primary key.
      refresh ((AgentPK) context.getPrimaryKey ());
    catch ( FinderException fe ) {
      throw new RemoteException (fe.getMessage ());

  private void refresh(AgentPK p_pk) throws FinderException, RemoteException

    // If the EJB has not been modified, don't refresh it & short circuit!
    if ( !isModified () ) {

      logDebug("refresh: short circuited reloading of entity.",100);
   ..........//do database connection and query ...//

  //set this instance not to be refreshed again

   Now in my client side,  we want to refresh the bean - loading most recent
data from database so that on the gui we will see the most recent data.
However, I cannot just change setModified(false) to true at the end of the
refresh method because that way I always get unnessary refreshes. My
difficulty is I cannot use setModified() directly in my client code because
I have only the pk or remote interface.
How and where would be appropriate for me to set the modification flag to

  Thank you in advance for your help.

Question by:sihu

Expert Comment

ID: 6246148
One way you could solve this would be to define a service class and interface for your bean in a manner similar to the one described in the artcle:

Universal Wrapper for Entity Beans by Andrei Povodyrev and Alan Askew.
Java Developers Journal June, 2001.

The article describes a parent class and interface that allows you more flexibility in the definition of you beans than the dafault specs allow for.

With the added flexibility, you could change the modify class in a service class method and have it delegate to refresh.


Expert Comment

ID: 6246156
By the way, you can read the article by downloading the electronic copy of the magazine issue at:

LVL 19

Expert Comment

by:Jim Cakalic
ID: 6246227
Hi, James.

My instinctive reaction is to say it sounds like you have a design/implementation defect. Either the bean values _can_ change at any time, in which case you have a high probability of defective behavior because of the caching implementation, or they _can't_ change in which case you don't really have a problem.

Really, bean value caching is a responsibility that you should leave to the container. The EJB specification defines three kinds of Entity EJB caching that can occur. Option A caching allows the container to assume that it "owns" the database. Changes will not occur except through the EJB instances of a single container. As such, the container can read the EJB state once and then hold it between transactions. Option C caching is exactly the opposite -- EJB state must be refreshed at the beginning of each transaction and flushed at the end of a transaction. Option B is a somewhat confusing "middle-ground". Depending on your container, it may support some or all of these options.

So -- 1) determine whether the bean values can change and 2) determine the commit level caching option of your container. If your bean values can change external to the EJB container then the current caching mechanism is likely a defective optimization that should be removed. If bean values cannot change except through the entity EJB, you have only one container instance in your deployment environment, and your container supports Option A caching, then remove the "custom" caching in favor of container-managed cache. Either way you don't want clients to be forced to know when they must refresh bean values.

For reference, the EJB specs which describe the commit options are available here:

Best regards,
Jim Cakalic
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 6248663
Thank you jpk and Jim,

   Jpk, I can have a simpler option to set a refresh flag when I load my hierarchy in the cache. The problem now is after I have updated the bean data on serverside, my client side(gui) still gets the old data. I wonder there must be two sets of data in the cache and even though I log out and relogin as a new user, I still cannot get the latest data that have been updated on the server side.

  Are they cached to different places?


Expert Comment

ID: 6249553
What application server are you using?

When you log out the entity been shoud be returned to the object pool, when you reaquire it, after an ejbActivate() call, ejbLoad() is called inmediatley.

This leads to three possibilities I can think of:

1.- Your code to modify the value of your flag is not working.

2.- Yur application server uses some form of environment property to handle entity bean persistance and you are not setting it correctly

2.- Your app server cashes the DB calls (example Oracle IAS9i) and you have incorectly set the app servers cahe configuration.

Of these three, option 1 and 2 seems the most likely.


Author Comment

ID: 6250557

 I looked into my code again. My gui side getting data via a Proxy which implements the remote interface of my bean. In this proxy class, there is a updateCache(EJBChangeEvent _event) method, which is supposed to update the cache when bean changes. But I did not see wherever this method is called. Actually I guess the cache was not updated at all. This may be hard for you guys to figure out without looking into the code. Any of you have experience using a proxy class to update cache?

Author Comment

ID: 6253328
Hi jpk, to answer your question, I am using weblogic 5.1.
The flay problems I have solved. I guess my problem now is to figure out why the proxy is not working in updating cache.

Author Comment

ID: 6259794
Hi Jim and JPK,

  Thank you for your responses. After reading your comments and reading weblogic documents, I did not see I should do anything with my deployment xmls. Here I'd like to post them to you so that you may give me better directions. Thank you.
*********** **
* ejb-jar.xml

<?xml version="1.0"?>

<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>


<?xml version="1.0"?>

<!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 5.1.0 EJB//EN' 'http://www.bea.com/servers/wls510/dtd/weblogic-ejb-jar.dtd'>

LVL 14

Expert Comment

ID: 9017836
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

[paq'ed/points refunded]

Please leave any comments here within the next seven days.
EE Cleanup Volunteer
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.

Accepted Solution

YensidMod earned 0 total points
ID: 9115461
Question is PAQ'd and points refunded.

Community Support Moderator @Experts Exchange

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question