JPAContainer won't save Entity changed directly

Hi Folks,

I’m trying to save changes to an Entity managed by JPAContainer which I’m making directly on the Entity object, but JPAContainer refuses to save the changes.

Here is the approximate code:


container = new JPAContainer<Person>(Person.class);
	    
	    MutableLocalEntityProvider<Person> entityProvider =
		    new MutableLocalEntityProvider<Person>(Person.class,
			    				getEntityManager());
	    // Avoid org.hibernate.LazyInitializationException
	    entityProvider.setEntitiesDetached(false);
	    container.setEntityProvider(entityProvider);

// Get the personEntity from the container
EntityItem<Person> personEntity = ...

Person person = personEntity.getEntity();
// Addresses is a one-to-many List of Address objects
person.getAddresses().get(0).setAreaCode("123");

	    log.debug(m, "Entity isDirty=%s isModified=%s isPersistent=%s", 
	              personEntity.isDirty(), personEntity.isModified(), personEntity.isPersistent());

personEntity.commit();
personEntity.getContainer().commit();

The debug output shows:
Entity isDirty=false isModified=false isPersistent=true

The changes are never saved back to the datastore though the running container instance does show the change.

So it looks to me like the container doesn’t believe the object has changed. Is there same means of forcing the container to think this entity isModified=true or isDirty=true? Or perhaps some other method all together?

Hi,

The item (and its container) can’t know it is changed so it does nothing. You could do a standard JPA merge calla to save changes if you modify the bean “manually”. If the modification happens via the Property API everything should work fine.

If I don’t remember wrong, somebody had bit similar problem lately. He was doing the merge but then updates didn’t appear in UI (Table listing the db). For that case one can now (in JPAContainer 2.0 snapshot builds), fire property value change events manually.

BTW, JPAContainer 2.0.0 snapshots (for AGPL version) are available at:
https://oss.sonatype.org/content/repositories/vaadin-snapshots/com/vaadin/addon/jpacontainer-addon-agpl-3.0/2.0.0-SNAPSHOT/

All input for next version is highly appreciated atm. We’ll be targeting features for the next release soon.

cheers,
matti

Hi Matti,

Thanks for your thoughts on this.

What I wound up implementing was to reload the table with a new JPAContainer instance. JPAContainer doesn’t have a refresh() method which would be REALLY helpful. I saw a few posts about people trying to jpaContainer.setEntityProvider(…same entity provider again…) to get the container to reload, but that didn’t work for me with jpacontainer 1.2.1. Hence I now create a new JPAContainer instance and table.setContainerDataSource(…). Very brute force but I didn’t see any other way around this.

This will be a problem later for us when we have tables with thousands of rows. So we really do need some way of telling JPAContainer to refresh one entry (row).

mike