users@glassfish.java.net

Re: Questions on EJB 3.0 and data retrieval.

From: <glassfish_at_javadesktop.org>
Date: Thu, 10 May 2007 09:52:30 PDT

> I am testing EJB 3.0 and have one question.
>
> If I retrieve and entity bean (it does a database
> lookup). It pulls the latest information from the
> database.
>
> But if I make a change to the data in the database
> externally, when I do a read on the entity bean again
> it doesn't find the changes. I guess the EJB is being
> cached. But is there a way to have it detect the
> changes to that row and reload the data?

I have similar problem.
To refresh list of patients I'm using this method:

@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public String newPatientRefresh() {
    if (patientList != null) {
      patientList.clear();
    }
   patientList = patientService.findNewPatients(getDate(), providerId, insuranceType);
   return null;
}

Keep in mind that in patientList stored detached entities because I'm using container managed entity manager. And I cleared the collection and after that used jpql query to get refreshed entities from database. Still I get fresh data only in case I rerun application.
The method located in jsf bean that has session scope but I don't see reason why application kept old state of entities. Anyway I cleared the collection and I know that call method "clear()" of entity manager make sense only in application-managed or extended persistence contexts that are long lived. Even in this situation running query should be enough to get refreshed entities.

> cached. But is there a way to have it detect the
> changes to that row and reload the data?
I doubt there is a way to know that changes was made in database.
Just use timer and rerun query to get fresh data.
Only problem is I can't get fresh data anyway ;)
Maybe I have to do more testing to make sure that problem is on container side.
And report the issue if I still can't get fresh entities.
[Message sent by forum member 'vladperl' (vladperl)]

http://forums.java.net/jive/thread.jspa?messageID=216351