• Post Reply Bookmark Topic Watch Topic
  • New Topic

MDB question...

 
atul khot
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings all...
My first post ;-)

I have an MDB which gets/processes a dto. I am using container managed transaction. As I understand, this puts the onMessage() method under transaction.
Now some exception is thrown (so the onMessage() aborts). This will make the container restart the transaction. So the same dto is pushed back on the queue and is again processed by onMessage().
Now, given all this, I am ***changing the dto*** before the exception happens... Can I preserve this change when the next transaction is started.
After playing with this, I came to know that the transaction is restarted with the original dto (the changes are not preserved...).
I understand why this happens (as a transaction restart should start with a clean state - flat transaction semantics etc...).
Is there some way to achieve this?
Why I need this is there are some application specific activities (sending sms to a cell) which should happen only once - and the database update (which could happen again and again - till it succeeds).
However, in my case,
onMessage() {
dto = ...
...
if (!dto.getMessageSent()) {
send(message); // should happen only once
dto.setMessageSent(); // turns on a flag in dto - this should be preserved.
}
writeToDb(); // can throw and could restart the transaction
...
}

is there any way to get this behaviour? Thanks for any pointers, comments etc...

(Let me know if this is vague in any way and I would gladly post some code snippet ...).

--- thanks atul
 
atul khot
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
Another idea to solve this is to split this into two MDBs... however, I am still wondering if there is any way I can pass this state across a transaction restart...

--- thanks atul
 
atul khot
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I got the same effect by using Bean managed transactions and using javax.transaction.UserTransaction...
This complicates the code a bit but seems a good approach. Let me know if I am missing anything else (or any other suggestions/tips most welcome ;-).
This is pretty exciting stuff ;-)

--- cheerio atul
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!