-
1. Re: Error: CMR Collection only used within transaction
sesques Mar 2, 2004 8:33 PM (in response to luigifonti)Hi,
Effectively, a collection returned by a getter on a CMR field can only be used within the initial transation (created during the EJB getter call).
You should set the transaction type to "required" for your getter method, and test your code within this enveloppe:
UserTransaction tx = null;
InitialContext ctx = null;
boolean rollback = false;
try {
ctx = new InitialContext();
tx = (UserTransaction)ctx.lookup("UserTransaction");
tx.begin();
// Do your thing
} catch (Throwable ex) {
// Maybe set rollback = true if needed
} finally {
try {
// Close the InitialContext
if (ctx != null) {
ctx.close();
}
// Must always remember to commit or rollback.
if (tx != null) {
if (rollback) {
tx.rollback();
} else {
tx.commit();
}
}
} catch (Throwable ex2) {
// Big problem if falls there !
}
}