Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Transactions in message driven beans  RSS feed

 
Lahiru Abeydeera
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI, Im using java ee 5. i want to send database inserts to the database throught a message queue to ensure the order of insertions.


clients invokes a stateful session bean to send the data. and the bean will access the message driven bean which is responsible for the actual db insert. all the calls through a single stateful bean is in one transaction. if one of the inserts fail the transaction should rollback.

but the problem im facing here is the SQL connection used to the updates cannot be passed from the session bean to the message driven bean since the conncetion is not serializable.

Can any one help me with a solution to this problem.
 
Sumit Malik
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lahiru Abeydeera

Well, here i m not clear why you want to pass sql connection to MDB. Can't you just create a new connection through MDB or use a datasource(through dependency injection) to update the values in DB.

Do let me know if you have any problem in this way...

Cheers !!!
Sumit
 
Lahiru Abeydeera
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to pass the connection because i want to maintain the transaction. thats why the session has to pass the connection to the MDB. is there any other better way of doing this?

thaks for the interest.
 
Sumit Malik
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Lahiru Abeydeera

I do believe that you must be doing your business implementation in this way

1. From stateful session bean you are just calling message driven bean and in MDB using entity manager(or datasource) you are inserting new values to DB.
2. For updation same way you are folowing...

Well, if you are invoking entity manager(or by datasource) through MDB then i dont believe there is any problem because i hope you are making you business method's with MANADATORY transaction attribute there itself...
If you are following above then i dont see you have to pass sql connection to MDB because you are creating it in MDB itself.

So just do DB specific operation(invocation of SQL connection,create,update,delete operation) in MDB and let the session bean talk to MDB..


Do let me know if i have got to your point or you can post your code snippet so that i can have a look on it.

Cheers,
Sumit
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!