I am going to apply the following changes as a fix:
- flushCache() is going to evict only instances that currently are not in use, leaving instances in use in the cache until the transaction commits.
- add a new element to the container-configuration: store-not-flushed. The value of the element indicates whether dirty instances that could not be evicted from the cache after flushCache() should or should not (to prevent potential data inconsistency) be stored at sync time. The default value is true (the way it has worked until this moment). Setting it to false will result in an EJBException at sync time for modified instances (note: this doesn't affect not modified instances and the invocation of ejbStore on them).
Note, the changes affect not only flushCache (which can be called programatically, by option-D-refresh thread or cache invalidation manager) but also time-based eviction policy.