-
1. Re: 500 A CMR collection may only be used within the transct
ahjulsta Jan 23, 2002 7:11 AM (in response to ahjulsta)Sorry, should have read the spec more carefully.
This solves the problem:
UserTransaction trans = new InitialContext().lookup("java:comp/UserTransaction");
trans.begin();
// do stuff
trans.commit();
Being spoiled with CMT when writing beans dulls my brain.. :-)
However, one problem still remains:
I use a MVC pattern, with a JSP view, servlet controller, and EJB Local-objects as the model. After having made changes to the data in the controller (servlet), and redirecting to the jsp page, the changes are not visible yet. A reload (1/2 sec afterwards) gives me the desired data.
What can be done to fix this?
(And BTW, when experiencing the previous problem, the response was not consistent. Sometimes it could work; after some irrelevant code changes (outputting more html), it wouldn't. Could this indicate that there is a timing issue of some sort related to the transaction manager? I'm using CVS as of January 18th, just before Marc Fleury started committing the UnifiedDeployer.. ) -
2. [Jboss3.0.2] A CMR collection may only be used within the tr
ardochoke Sep 2, 2002 2:05 AM (in response to ahjulsta)I have an application that worked in JBoss 3.0.0 and I moved to 3.0.2 to try and fix an unrelated problem.
Now my existing code is giving me the following error:
java.lang.IllegalStateException: A CMR collection may only be used within the transction in which it was created
I have two CMP Entity Beans (User and Roles). These are connected with a Many to Many relationship.
My ejb-relationship looks like:
<ejb-relation>
<ejb-relation-name>User-Role</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>user-has-roles</ejb-relationship-role-name>
Many
<relationship-role-source>
<ejb-name>UserEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>roles</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>role-has-users</ejb-relationship-role-name>
Many
<relationship-role-source>
<ejb-name>RolesEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>users</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
In all the CMP examples I have looked at no one seems to play with the transactions directly - which seems to be what this thread is suggesting? I have both EJB's in <container-transaction> section and <trans-attribute> set to Required.
The code snippet is:
// OK
UserLocalHome myUserHome = getUserLocalHome();
UserLocal myUser = myUserHome.findByPrimaryKey(username);
// OK
RolesLocalHome myRoleHome = getRolesLocalHome();
RolesLocal myRole = myRoleHome.findByName(roleName);
// Exception thrown on this line
if( myUser.getRoles().contains(myRole) ) {
I have spent many hours searching forums, etc. but I wouldn't be suprised if I'm just doing something stupid...
Any advice would be greatly appreciated.
Regards,
Adrian -
3. Re: [Jboss3.0.2] A CMR collection may only be used within th
dsundstrom Sep 2, 2002 1:25 PM (in response to ahjulsta)The code needs to be wrapped in a transaction using either a UserTransaction or a SessionBean.