• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing CMR collection from servlet  RSS feed

 
Sandeep Ghosh
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I have a many to many relationship which is returning a collection. When I am accessing that collection from servlet it is giving this exception.
14:45:14,176 ERROR [STDERR] java.lang.IllegalStateException: A CMR collection may only be used within the transction in which it was created When I am accessing it from my session bean it working fine. Is there anyway I can access from servlet.
Thanks in adv.
Sonu
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Stack trace and the EJB spec say the same thing:

A CMR collection may only be used within the transction in which it was created.

Your entity beans have a transaction attribute of "Required"?.
Since no transaction is being started from within the servlet, the CMR gets realized in the new transaction started by the entity bean method.
U need to be starting a transaction from within your servlet before accessing the CMR. I *think* a UserTransaction started by a servlet will get propogated to the CMT of the entity bean.
If you do that you s'd not have a problem accessing the CMR within the UserTransaction started by you.
Your session bean must also be having a transaction attribute of "Required" , so you are able to access the CMR within the session bean.
 
Sandeep Ghosh
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks your suggestion solved my problem. I have done this

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