I'm using Jboss 6.1 together with Hibernate and HornetQ. If I manipulate Data in my Database and add a message to the Queue that relies on the data changed just before I don't want that message to be processed before my data has been actually committed to the DB. So in order to avoid a race condition I'd like to get HornetQ into my Container Managed Transaction so the message would only be "committed" to the queue when the global Transaction is also committed.
Is this possible ? Any hints ?
It is possible. You will need to use an XA transaction so you get a 2 phase commit so:
The easiest way, I have found, to validate that you are in fact running a 2PC transaction is:
If the transaction is an XA 2PC, that field (which is a Hashtable) will contain 2 XAResources as keys, one for JMS and the other for JDBC.
I don't know which architecture you're most familiar with, but I would think that a container managed transactional stateless session EJB would be the easiest way to do this.