JPAContainer - clear cache?

I have a JPAContainer loading data from a database table. One of the fields in the table is named ‘recType’. Within my program I have an option to delete all records where recType = 2; This works fine.

However, I have an external program that will occasionally update the database and change a recType value. If I run my Vaadin program and delete all the records of type 2, and then run my external program and create another type 2 record, my web program will not recognize it. It looks like it can’t reload the original database values. I can log off and back in and it still won’t reload the data correctly. If I stop and restart Tomcat (and thereby reload the .war file) then it picks up the modified data.

So is there some way to tell the JPAContainer to flush its cache and reload itself from the data in the database? I was hoping this was something simple, but I have not been able to figure it out…

Thanks,

nbc

add a function to your jpacontainer that updates its data from the databas and call the function?

That’s what should happen when I log off and log back in to the program - I think I’m reloading the data from the database - but it looks like the data is getting cached someplace… I’ll dig deeper and see if it is somehow bypassing the database call…

nbc

There are several different levels of caching.

The lowest level caches inside the database and the JPA implementation should not be a problem here, but the JPAContainer also does something you could call caching, and its entity provider may as well. In addition, the display component like Table will not do a full refresh if it does not get a notification of change.

The JPAContainer “cache” you can flush (if I remember correctly) by (re-)setting its entity provider - even with the same instance as it already had. Likewise, the “cache” in Table can be refreshed at least by (re-)setting its data source.

Clearing the cache of an entity provider depends on the entity provider in use - e.g. CachingEntityProvider has the method flush().

Some of the lower level operations may propagate to higher levels, but CachingEntityProvider.flush() does not automatically trigger a notification to containers using the provider.

For anyone else having this issue, I was able to solve this problem by adding:

<shared-cache-mode>NONE</shared-cache-mode>

in my persistence.xml file for my JTA data asource.

Very interesting - I will definitely give that a try - thanks!

nbc

try this instead before you create your vaadin container

[code]
entityManager.getEntityManagerFactory().getCache().evict(entityClass);

[/code]

this clears the cache for a particular entity, as opposed to disabling caching for all entities.

Setting shared cache mode to none in persistence.xml fixed the issue. Thanks.

 <provider>
          org.eclipse.persistence.jpa.PersistenceProvider
      </provider>
      <exclude-unlisted-classes> 
        false 
    </exclude-unlisted-classes>
    <shared-cache-mode>
        NONE
    </shared-cache-mode>

Hello guys,

I was experiencing the exact same problem and was able to solve it using the following code:

entityProvider.flush();
entityTable.refreshRowCache();

Can anybody confirm this is a valid solution?

Thx!

Regards,

Kim