I am trying to use the SessionSynchronization interface on a stateful session bean so it can reload its state from the database. The afterCompletion method appears to be called when the transaction commits, but I have trouble reading the database from this method.
If I hit the database (by calling findByPrimaryKey from an entity bean) from the afterCompletion method, it complains that the transaction has already been committed.
If I force it to start a new transaction by doing the lookup from a session bean with a transaction attribute of RequiresNew, it sees the data from before the transaction commit; in this case, it does not find the row that I know the transaction inserted. (The insert statement was logged, and the data shows up in the database.)
Is this a bug in JBoss? How can I be notified of transaction commits at a time when I can see the changes the transaction has made?
Thanks for your help.
If you want to work within the same transaction you need to use the "before completion".
If you want to see the database changes maybe it is simpler to use a new bean as opposed to your convoluted bean scheme.
If the JBoss didn't store data in the db don't you think it would be a big story long time ago on the user lists?