• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MDB question...

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Did you miss me? Did you miss this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic