| Some appserver vendors claim that if data of entity beans changes in the database, they will refresh entity beans cached in the container. Does Borland support anything like this? |
|
Possibility 1: What some Containers could do is, while the cached EJBs were NOT involved in a transaction, a background thread in the container would walk through the list of cached EJBs (periodically) and check if their data was changed in the database and, if so, refresh them. Unfortunately, this approach is broken. Say then, at time t1, the container verified that the database and cache were in sync. Then say at t2, the container starts a new transaction and uses the up-to-date cached state. Also, let's say at t3, a legacy application changes the data in the database. The problem occurs if t3 comes between t1 and t2. The container thinks the cache is up-to-date and in fact it is not. When t3 falls between t1 and t2, the legacy application's changes are potentially wiped out. The only way to solve this problem is to check the database before starting the transaction. This is exactly what we were trying to avoid in the first place! Unfortunately, ACID properties are nasty. You just can't cheat! So again, any vendor that claims they solve this problem is either:
Persistence's application server claims to use optimistic concurrency control attributes (OCAs) to detect the case where t3 fell in between t1 and t2, in which case the database would have a higher OCA value than the cached EJB state, and the EJB transaction would either fail with a special concurrency-control exception, or wipe out the legacy application's changes (configurable). Possibility 2:
|