I want to cache entity beans using Option A but do not have “exclusive” access to the database for short, well defined periods. Can I workaround this in any way?

Expanded Question:

I want to use Option A but I need to give up “exclusive” database control for occasional DBA tasks. Is there any way of:

(a) Dynamically turning off caching? Is there an IAS API for accessing the container and telling it to unload the cache for some beans at a specified time? This would be useful in situations where it makes sense to enable container caching but where there are (infrequent) external modifications of the database by administrators (for example, cleaning up a screwed-up transaction, running a batch process to delete expired accounts, whatever). It makes container caching more usable/useful in situations where it's a selling point.

(b) Being able to send a message forcing state to be resynchronized?

(c)The ideal might be some means by which an administrator could turn it off while an external task is running. A typical user scenario is as follows:

We are at present using the ejb.transactionCommitMode=exclusive flag for all of our beans. But for some beans we have an issue that we each night perform a database synhronization with our switches’ internal routing tables. At present this update is done directly to the database outside of the entity beans. The update takes 15 minutes and is done in the early hours so we do not expect any user issues but because the container could be possibly be caching the relevant beans when the user logs on in the morning they would not get the correct view. Now we could get rid of this flag but then we sacrifice our performance gains for the sake of 15 minutes update. What options do I have?

Answer:

The Container has the ability to dynamically add and remove EJBs from a running container. You can do the following:
  1. Run the beans as normal in exclusive mode.
  2. Do the update.
  3. Remove the old EJBs and add the same EJBs back to the running container.

This will effectively clear the cache and update the entities.

If you are unhappy with having the beans be inconsistent for the duration of the update, then you can do the following:

  1. Run the beans as normal in exclusive mode.
  2. When you want to do the batch update, substitute versions of the beans running in shared mode for the beans running in exclusive mode.
  3. Do the update.
  4. Substitute the exclusive mode beans for the shared mode beans.

We provide a command-line interface which can be used to load and unload beans from a running container. So, it should just be a matter of adding these commands to your existing batch run.