• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access CMR-fields in SessionBeans  RSS feed

 
tina kinger
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
Iam accessing a cmr-field in an entity bean,inside a session bean.But iam thrown an IllegalStateException while doing this.The error message was 'attempted to access a collection valued cmr-field outside the scope of transaction.'
Can anybody help me solving this?
Thank You --- Tina
[ November 23, 2003: Message edited by: tina kinger ]
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure your Session bean methods and your Entity bean methods all have a transaction attribute of "required".
Kyle
 
tina kinger
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
It worked well.
I have previously set the attribute value of the sessionbean to 'supports'.
Can u please explain why is it necessary to set the attribute value to required.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, this gets into why CMT (Container managed transactions) are necessary. If you set the attribute to "Supports" then you're saying "If there's already a transaction around, I'll use it, but if there's not I don't care". That means that your Entity bean methods run outside of a transaction, since you didn't create one, which caused your error.
By using "Required" you changed that to "If there is a transaction, I'll use it, but if not, then I'll start one".
Kyle
 
tina kinger
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Kyle.
Tina
 
Sany Bel
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting the same error when I try to access a cmr field from my jsp. I am retrieving the collection in my action class and passing it to the jsp as a request parameter. All my bean methods have their transaction attribute set to "required". I do not know how to make my jsp use the same transaction. Did anybody face this problem. Any help would be greatly appreciated.
Thanks,
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't return a collection of EJB's retrieved from a CMR outside of your Session bean. When you do that it places the access of that collection outside of the transaction scope of your session bean.
You should only ever return collections of Value Objects (Data Transfer Objects) from Session beans. See this article for an example.
Kyle
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kyle,
Have u published any books using Weblogic? If yes let me know their names.
If possible let us know the books published by u so far other than the one mentioned in ur post.
Seetesh
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not able to access ur site http://www.kyle-brown.com/ from India.
Seetesh
 
Augg Stine
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is accessible from Chennai, India
 
Sany Bel
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not using a Session Facade pattern. There is no Session bean between my entity bean and jsp. All I have is a struts action class.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sany Bel:
I am not using a Session Facade pattern. There is no Session bean between my entity bean and jsp. All I have is a struts action class.


Yes, and that is the cause of your problem. You cannot access CMR relationships outside of a transaction. Thus, you need a Session bean to act as a Facade.
Kyle
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!