-
1. Re: A CMR collection may only be used within the transction
aloubyansky Oct 9, 2002 3:46 AM (in response to mozheyko_d)As it says: the collection is obtained in one transaction and then used in another. This is disallowed.
If you don't see the reason, post the code where the collection is obtained and used. -
2. Re: A CMR collection may only be used within the transction
minamoto Oct 9, 2002 4:25 AM (in response to mozheyko_d)>This is disallowed.
by EJB 2.0 spec.
See section 10.3.8 & 10.4.2.2.
Miki -
3. Re: A CMR collection may only be used within the transction
mozheyko_d Oct 9, 2002 4:36 AM (in response to mozheyko_d)How i can use CMR-METHOD getUserPays from my example ?
-
4. Re: A CMR collection may only be used within the transction
aloubyansky Oct 9, 2002 1:24 PM (in response to mozheyko_d)Wrap all the logic in one transaction.
-
5. Re: A CMR collection may only be used within the transction
iris Oct 24, 2002 6:32 AM (in response to mozheyko_d)Miki said: looking in the EJB 2.0 spec chapters 10.3.8 and 10.4.2.2.
I read those and they say:
"It is the responsability of the Container to throw the java.lang.IllegalStateException if an attempt is made to use a java.util.Iterator for a container-managed collection in a transaction context other than in which the iterator was obtained."
But in my code I use the iterator in the same method that
I obtained it and the exception is thrown.
Here is my code:
My User EJB:
/**
* This interface defines the local interface for the User Bean
*/
public interface User extends EJBLocalObject {
public Integer getId() ;
public String getName() ;
public String getPassword() ;
public Collection getProfiles() ; <-- CMR collection
}
public abstract class UserBean implements EntityBean, Principal {
private EntityContext context ;
// Access methods for persistent fields
public abstract Integer getId() ;
public abstract void setId(Integer id) ;
public abstract String getName() ;
public abstract void setName(String name) ;
public abstract String getPassword() ;
public abstract void setPassword(String password) ;
// Access methods for relationship fields
public abstract Collection getProfiles() ;
public abstract void setProfiles(Collection profiles) ;
....
}
My Profile EJB:
/**
* This interface defines the remote interface for the Profile Bean
*/
public interface Profile extends EJBLocalObject {
// Access methods for persistent fields
public String getTitle() ;
}
/**
* This class contains the implementation for the methods specified in the home
* and local interfaces for the "Profile" EJB
*/
public abstract class ProfileBean implements EntityBean {
private EntityContext context ;
// Access methods for persistent fields
public abstract Integer getId() ;
public abstract void setId(Integer id) ;
public abstract String getTitle() ;
public abstract void setTitle(String title) ;
...
}
The code in which I use the CMR collection:
try {
Collection tmp = userHome.findByName(userName) ;
if ( tmp == null || tmp.isEmpty() ) return null ;
User user = (User)tmp.iterator().next() ;
System.out.println("User: "+user.getName()) ;
Collection profiles = user.getProfiles() ;
ArrayList principals = new ArrayList() ;
Iterator it = profiles.iterator(); // <-- here
for (; it.hasNext();) {
Profile profile = (Profile)it.next() ;
System.out.println("profil: "+profile.getTitle()) ;
principals.add(new MyPrincipal(profile.getTitle())) ;
}
return Collections.enumeration(principals) ;
} catch (FinderException find) {
System.err.println("FinderException") ;
return null ;
}
The exception is thrown on the line Iterator it = profiles.iterator(); // <-- here
so when I attempt to get the iterator, this not act as
described in the specification.
Is this a bug ?
Iris