I have an entity that has a CallBackListener registered using postPersist and postUpdate. The listener takes the entity and submits the ID to a JMS queue which perform further processing. The message submission and consumption are so fast that they're occurring before the original session has completed it's transaction.
As a result the MDB either can't find the entity or the entity is stale. What I 开发者_开发百科really want is a way to have the MDB check to verify that the original transaction is complete before consuming the message.
Any suggestions?
You might be able to register an instance of org.hibernate.Interceptor
with the SessionFactory
or Session
, and post the message to the queue in the afterTransactionCompletion(Transaction tx)
method after consulting Transaction.wasCommitted
. In the afterTransaction
method you might have to access the ID of your entity in some global threadlocal.
精彩评论