I think the following part of the documentation about the JTA support answers most of your questions:
Using a JTA Cache
All or nothing
If a cache is enabled for JTA all
operations on it must happen within a
transaction context, otherwise a
TransactionRequiredException
will be
thrown.
Change Visibility
The isolation level offered in Ehcache
JTA is READ_COMMITTED
. Ehcache is an
XAResource
. Full two-phase commit is
supported.
Specifically:
- All mutating changes to the cache are transactional including
put
,
remove
, putWithWriter
,
removeWithWriter
and removeAll
.
- Mutating changes are not visible in the local JVM to or across the cluster
until
COMMIT
has been called.
- Until then, read such as by
cache.get(...)
by other transactions
will return the old copy. Reads do not
block.
Write-behind and Write-through
If your XA enabled cache is being used
with a writer, write operations will
be queued until transaction commit
time. Solely a Write-through approach
would have its potential XAResource
participate in the same transaction.
Write-behind, while supported, should
probably not be used with an XA
transactional Cache, as the operations
would never be part of the same
transaction. Your writer would also be
responsible for obtaining a new
transaction...
Using Write-through with a non XA
resource would also work, but there is
no guarantee the transaction will
succeed after the write operation have
been executed successfully. On the
other hand, any thrown exception
during these write operations would
cause the transaction to be rolled
back by having
UserTransaction.commit()
throw a
RollbackException
.
Regarding performances, I wouldn't worry too much unless your object weights hundreds MB. But if this is really a concern, measure things (as always).