Skip to main content

entitymanager refresh & j2se

3 replies [Last post]
markbrazil
Offline
Joined: 2004-07-26

I have a j2se application.

For running copy #1 - I change data in one screen and use entitymanager merge, flush and refresh. The data then updates nicely in other screens.

This all works well for the one entity manager.

I have used one entity manager per j2se app.

However, as it's a j2se application. Two people can run their own copy. With 2 copies open (each own entitymanager).

Sequence of events
- data has been queried in running copy #1
- data queried, and changes are made in running copy #2.
- requery for app copy #1, No changes show !

Any idea's on how I can fix this ?

The data is obviously cached. Requery time is very fast !

Can I turn off the cache ? (and how would I do it?)

Thanks,
Mark.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ss141213
Offline
Joined: 2005-03-30

Does [b]entityManager.refresh()[/b] not refresh the data in app #1?

Sahoo

markbrazil
Offline
Joined: 2004-07-26

It works if I always do a em.refresh(obj) for every row I fetch from the database.

As I don't know what data changes, it will mean I have to put a em.refresh(obj) on every query I have.

My query was :-
List bales = null;
bales = query.getResultList();

Now becomes
List bales = null;
bales = query.getResultList();
for (Bale bale : bales)
em.refresh(bale);

The time for a new query obviously multiples out as I'm doing the whole thing twice.

Performance is an issue, but it does work.

Thanks for your help.
Mark.

> Does [b]entityManager.refresh()[/b] not refresh the
> data in app #1?
>
> Sahoo

ss141213
Offline
Joined: 2005-03-30

OK. I now understand your problem. There are ways to configure TopLink cache as you can see from the [b]toplink.cache-usage[/b] property mentioned in https://glassfish.dev.java.net/javaee5/persistence/entity-persistence-su...

But I don't know what the values mean. I will see if any one from our team knows what value you can use. Of course, you can also find out by trial and error.

Thanks,
Sahoo