Refresh/reload EntityItem from JPAContainer

Hi Folks,

I would like to know how best to reload/refresh an EntityItem in a JPAContainer.

Let’s say I have a class called Person which is managed by a JPAContainer. If I make changes to a given Person object outside of JPAContainer I want to tell the JPAContainer instance to refresh/reload just that one specific Person object and not reload the entire
container (since there may be thousands of records).

Here is one way I was thinking of:


EntityItem<Person> personEntity = ...;
Person person = personEntity.getEntity();
... make changes to person
JPAContainer<Person> container = personEntity.getContainer();
container.removeItem(personEntity.getItemId());
container.addEntity(person);
container.commit();

Is this the best way of going about this?

Hi,

I guess there is currently now “right way” to accomplish that. I created an enhancement ticket about it:

http://dev.vaadin.com/ticket/7869

__
cheers,
matti

As far as I can recall, at least with JPA 1.0, there is no way to portably refresh and reattach an entity instance without possible side effects.

If it does not matter that the instance does not stay the same, it might not be so hard to add such functionality (famous last words…).

I think a method was added recently to JPAContainer to try to reattach an entity, but it can have side effects as it uses merge() internally if I recall correctly.