I'm trying to optimize db usage using read-ahead and optimize pessimistic locking using read-ahead beans, but these seem to be mutually exclusive, since the read-ahead beans and read-ahead methods don't participate in transactions so never use a pre-load cache.
For example, using JBoss 3.2.4RC1, with no read-ahead, I run a finder and then separately load each entity bean, generating N+1 db calls. I can remove these unneeded calls by adding read-ahead (either on-find or on-load), but then when I add read-only using either:
then I'm back to N+1 because the read-only methods don't particpate in the transaction so don't use the precached data.
Is there any way to address both of these issues without turning to optimistic locking? It seems like theoretically a read-only method accessed from a transaction could still be able to access the data in the preload cache without locking the bean...