*
The moose likes EJB and other Java EE Technologies and the fly likes A CMR collection may only be used within the transction in which it was created Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "A CMR collection may only be used within the transction in which it was created" Watch "A CMR collection may only be used within the transction in which it was created" New topic
Author

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

Jolie Lee
Ranch Hand

Joined: May 08, 2005
Posts: 87
i got the error above when i trying to get the collection size in my java bean.



and this is declared in my EJB:


my relationship in ejb-jar.xml:


any advise pls?


Jys<br /><a href="http://jy-s.com" target="_blank" rel="nofollow">http://jy-s.com</a><br /> <br />Trying my very best to learn java, please forgive me if i'm asking some really stupid questions.
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Assuming that you are accessing the entity beans from within a stateless session bean, make the transaction attribute as 'REQUIRED' for all the beans. That way you will be accessing the CMR in the same transaction in which you acquired it in the first place.
Jolie Lee
Ranch Hand

Joined: May 08, 2005
Posts: 87
I've already set the transaction as "Required"..

Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
How are you accessing the CMR? If its from within a java-bean and not an 'enteprise java bean' (SLSB for eg) then you will run into this error, because you probably are not starting a transaction before accessing the 'entity bean' in your 'java bean'. The entity bean , since it has a transaction attribute of 'required' will start a new trsnactoin. The CMR will be created in that transaction. but you are trying to access that CMR in a 'java-bean' which is NOT in the same transaction.

Enclosing the java bean method in a transaction may fix this issue



or better why dont you access the entity bean from with a SLSB facade as is the norm
Jolie Lee
Ranch Hand

Joined: May 08, 2005
Posts: 87
i'm accessing the CMR within a java-bean and not the EJB. reason being is my jsp page is reffering to my java-bean. How can i point my jsp page to directly get the value from the EJB?

anyway, i've tried the code u given and it works!! thanks a lot.

another question is, how do i display the collection? it should consists packageId and softwareID in this.packagesSoftware.

i've done something like this but it gives me error:


pls advise. Thanks.
 
wood burning stoves
 
subject: A CMR collection may only be used within the transction in which it was created
 
Similar Threads
2 primary keys??
Chapter 7 - HF study group
one-to-one relationship
Help me out for EJB2.0 CMR fields mapping in XDOCLET.......
URGENT HELP in EJB-QL USING WEBLOGIC 8.1