JPAContainer - cache update bug

There is a small bug in the JPAContainer
CachingMutableLocalEntityProvider
class.
Cache is not refreshed properly after entity is updated.
Digging deeper into JPA container and debugging of what is happening inside I was able to locate the source of the problem.
Issue can be easily fixed by switching order of two commands. Cache should be invalidated before entity is updated, so that change will trigger cache update.

Original code:

    @Override
    public T updateEntity(T entity) {
        T result = super.updateEntity(entity);
        cachingSupport.invalidate(
                getEntityClassMetadata().getPropertyValue(
                        entity,
                        getEntityClassMetadata().getIdentifierProperty()
                                .getName()), true);

        return result;
    }

Fixed code:

    @Override
    public T updateEntity(T entity) {
        cachingSupport.invalidate(
                getEntityClassMetadata().getPropertyValue(
                        entity,
                        getEntityClassMetadata().getIdentifierProperty()
                                .getName()), true);
        T result = super.updateEntity(entity);
        return result;
    }

After this change everything works correctly. I have this code fixed and running for a few months now, I just had no time to post this sooner.

If this is really a bug you fixed you could
contribute your code
.

Ok, I will do it :wink: