transaction boundaries and JMS
gmatthews Jan 4, 2004 5:38 AMAll,
I'm having trouble with transaction boundaries with JMS , and the JBoss Entity bean cache getting out of sync with the DB.
I have an application that primarily uses BMP Entity beans. I also have a scheduler service hooked up to fire off various JMS messages at certain intervals. When these 2 approaches try to update the same BMP Entity Bean, the JBoss cache seems to get out of date with the database.
The BMP Entity bean that i'm altering in this case represents a configuration item that a user may or may not have -- so it makes sense that the same data could be inserted or removed numerous times which would correspond to the user enabling or disabling that config item. Each bean has a compound key made up of the user's id and the configuration type id, e.g. 2-4 might mean that user 2 has config item 4 enabled.
Here's the MBean initiated sequence...
(1)
An MBean (via jboss scheduler) sends a message to a Message Driven Bean (via a Queue) which calls a Stateless Session Bean (using CMT) which tries to update a BMP Entity Bean.
(2)
This is ok at this stage, until I go back into my main web application and ejbRemove then ejbCreate the same BMP Entity Bean described above in (1)
(3)
When I do a findByPrimaryKey on the BMP Entity bean created above in (2), it has the same values as it did when it existed in (1), not (2) as I would expect. (what the!?)
The only (impractical) way I've found to fix it is open the jmx-console and press the flushCache MBean Operation for the particular Entity bean being edited. Of course this then lets JBoss reload state from the db and everything is ok.
Thanks very much,
Greg.
--------------------
Adrian, I've read the FAQ but it doesn't help. In particular, maybe this could be elaborated on slightly....
Question:
I am sending/publishing to a queue/topic in an EJB but it does not commit/rollback
when the EJB/JTA Transaction commit/rollsback.
Answer:
Use the JMS resource adapter connection factory bound at java:/JmsXA
Define "use". I'd be interested to see a good explanation on how to string together a series of MDB -> SLSB -> Entity bean calls wrapped in a single transaction.