JPAContainer and Optimistic Locking

Is there a way to configure a mutable JPAContainer such that changes to the database make use of JPA’s @Version and Optimistic Locking behavior to disallow the user from making changes to an entity that become stale?

I’m envisioning this scenario:

User1 views MyEntity(id=1, version=1)
User2 views MyEntity(id=1, version=1)
User1 commits change to MyEntity(id=1, version=1->2*) *version changes from 1 to 2
User2 commits change to MyEntity(id=1, version1) should generate an error message and update the table with current db contents.

Looking at the source code below for MutableLocalEntityProvider.updateEntityProperty(), it seems that JPAContainer circumvents Consistency Version Checking and Optimistic Locking by always refresh()-ing before applying the property change…virtually guaranteeing that an OptimisticLockException will never be thrown (it’s remotely possible if a change occurs in the database between refresh() and commit())

[font=Courier New]

            T entity = em.find(getEntityClassMetadata().getMappedClass(),
                    entityId);
            if (entity != null) {
                // make sure we are working with the latest versions
                em.refresh(entity);
                getEntityClassMetadata().setPropertyValue(entity,
                        propertyName, propertyValue);
                // re-attach also referenced entities to the persistence
                // context
                entity = em.merge(entity);
                em.flush();
                entityA[0]

= detachEntity(entity);
}

[/font]