Hello fgkalways
> I'd like email to participate in transactions
Servers that participate in XA transactions need to provide explicit support for doing so. Most database servers (JDBC) and message queuing systems (JMS) do so. These are termed 'resource managers' in transaction parlance. Many other useful services don't have this capability. The two most commonly cited such are the filesystem and email (SMTP). There are two approaches you can take to address this problem:
1) Write a resource manager implementation to wrap the mail server, leading the transaction manager to believe it is a transactional resource. You still won't have full 2PC, but it's better than nothing. As there is no way to recall a mail message once it has been sent (i.e. no rollback), you will also need to implement the 'last resource' gambit. This is an advanced approach suitable only for those with substantial transaction system experience. If you don't understand the idea don't try it unassisted.
2) Use exception handling in your business logic. It's less elegant but also much more straightforward:
beginHibernateTransaction();
try {
doHibernateStuff();
sendEmail();
commitHibernateTransaction();
} catch(EmailFailedException) {
rollbackHibernateTransaction();
}
As for transaction overhead, a good transaction manager will use lazy initialization. This means very little overhead, especially as such a small proportion of transactions are null ops.
Hope this helps
Jonathan
http://www.arjuna.com