Skip to main content

Problem with entity data synchronization

2 replies [Last post]
trouby
Offline
Joined: 2006-02-27

Hey,
How things going?

I have a problem with maintaining entity states which probably is very common,

Sometimes I end with entities which are not up to date,
This is usually happening when I work with entities that were already updated by other entity managers on the same time,

I was thinking that re-loading entities in places I must have the most updated data will solve the problem,

but even re-loading the data(by calling entityManager.find(class,id)... still loads the same old data,

How is the right way to solve this problem?

thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
markbrazil
Offline
Joined: 2004-07-26

two ways,

1) use entityManager.refresh(entity)

You'll need to do this for each row

2) can use hint on query (before executeQuery)

query.setHint("toplink.refresh", "true");

> Hey,
> How things going?
>
> I have a problem with maintaining entity states which
> probably is very common,
>
>
> Sometimes I end with entities which are not up to
> date,
> This is usually happening when I work with entities
> that were already updated by other entity managers on
> the same time,
>
> I was thinking that re-loading entities in places I
> must have the most updated data will solve the
> problem,
>
> but even re-loading the data(by calling
> entityManager.find(class,id)... still loads the same
> old data,
>
>
> How is the right way to solve this problem?
>
> thanks.

trouby
Offline
Joined: 2006-02-27

Hey,

As I understand both will try to refresh the entities first, but the problem is that the entity must be in a managed state before refreshing,

this is exactly my problem, if I merge the entity first, then the database will get updated with the old state of the merged entity.

thanks