oops - CMR in JBoss 3.0.1RC1
jayagovinda108 Jul 11, 2002 5:53 AMWe have CMR issues when trying to get a collection of local objects and convert them into value objects within the entity bean. Code and ejb-jar.xml at the bottom.
The exception thrown is:
2002-07-11 09:46:57,198 ERROR [org.jboss.ejb.plugins.LogInterceptor] Transaction
RolledbackException, causedBy:
java.lang.IllegalStateException: A CMR collection may only be used within the transction in which it was created
We had this working in previous releases. We are also not using commit option A in our jboss.xml.
Code: (the relationship between User and Role is M-M and is unidirectional - coming from User)
public User getUser()
{
User user = new User();
user.setUserId(this.getUserId());
user.setUsername(this.getUsername());
user.setPassword(this.getPassword());
user.setFirstname(this.getFirstname());
user.setSurname(this.getSurname());
user.setSuspended(this.getSuspended());
user.setCompanyName(this.getCompanyName());
user.setValidated(this.getValidated());
user.setAddress(this.getAddress().getAddress());
user.setRoles(collectionToVO(this.getRoles()));
return user;
}
public Collection collectionToVO(Collection a_colLocal)
{
Vector vecVO = new Vector();
Iterator iterator = a_colLocal.iterator();
while (iterator.hasNext())
{
RoleLocal local = (RoleLocal)iterator.next();
vecVO.add(local.getRole());
}
return vecVO;
}
ejb-jar.xml (relationship)
<ejb-relation>
<ejb-relation-name>User-has-many-Roles</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>UserBean UNIDIRECTIONAL</ejb-relationship-role-name>
Many
<relationship-role-source>
<ejb-name>UserBean</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>UNIDIRECTIONAL UserBean</ejb-relationship-role-name>
Many
<relationship-role-source>
<ejb-name>RoleBean</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
<ejb-relation>