views:

22

answers:

1

I have a web-app, which I deploy on Tomcat 6 and it uses Hibernate. It receives messages on a JMS queue which trigger changes both to my DB, via Hibernate and to an Object of mine (Agent).
The web-requests also access the DB, via Hibernate, and access the shared object (there's a ConcurrentHashMap<AgentId,Agent> held by a singleton).
My problem is that I have a JMS message which changes several different Agents and several tables and I need the changes in the Agents to be available if and only if the DB transaction completed successfully. In addition I do not want to employ read locks as that is too much of a performance hazard for me.
I was thinking of somehow implementing the XAResource interface for my singleton and then use JTA to manage both my singleton and my Hibernate transaction.
What do you think? Does it sound reasonable? Am I way off?

If any additional details are needed please don't hesitate to ask
Ittai

+2  A: 

Instead of implementing XAResource, you could use a transactional cache like EHCache which supports JTA since 2.0 (i.e. it can act as an XA resource and participate in a XA transaction alongside other XA resources).

Pascal Thivent
@Pascal, do you mean I should just have the EHCache maintain the above mentioned map?
Ittai
@Ittai Yes, exactly.
Pascal Thivent
@Pascal I have a performance concern regarding this solution which I posted about (http://stackoverflow.com/questions/3967111/how-does-ehcache-implement-its-transactions). I'd appreciate it I could receive your input.
Ittai