-
1. Re: Transaction scope with Session beans, flat classes and E
strathound Jul 7, 2003 6:52 PM (in response to krichards)Are you using Container managed transactions (transactions, not persistence) or User mananaged? If the former, then the transaction boundary is the EJB method invocation. For instance, if your session bean has a "foo()" method, the transaction would begin when the "foo()" method is called and ends when it returns. That means that all things the container knows about during that invocation are transaction aware. We use this to encompass both database and JMS events in our session beans. It all commits or it all rolls back.
In the case of user managed transactions, you set the transaction boundaries, so it's completely configurable. But you are responsible for beginning and ending the transactions. Don't goof it up. :)
HTH,
Michael -
2. Re: Transaction scope with Session beans, flat classes and E
haraldgliebe Jul 7, 2003 6:59 PM (in response to krichards)Hi,
the transaction is associated with the current thread of control, therefore it doesn't matter if you are calling the entity bean directly from the session bean or via some java classes.
Regards,
Harald -
3. Re: Transaction scope with Session beans, flat classes and E
krichards Jul 8, 2003 7:59 AM (in response to krichards)Thanks - The Session bean, and all the entity beans are container managed. I've checked my deployment descriptors and they seem to be okay, but I still get exceptions passed back from an EJB that don't cause a rollback.
At the moment I just have it set up so that one of my Entity beans has a null PK, so it always throws and EJBException on creation.
In rough form the code looks like
public class CommandEngineEJB implements SessionBean {
public CommandResultIF execute(Command cmd) {
return cmd.execute();
}
}
public Class exampleCmd() extends Command {
public CommandResultIF execute() {
// EJB calls
cntx = new InitialContext();
UserAccountLocalHome userlocalhome = (UserAccountLocalHome) cntx.lookup(UserAccountLocalHome.JNDI_NAME);
UserAccountLocal user = userlocalhome.create(null);
}
}
And a snippet from the jboss deployment descriptor looks like ...
...
<container-transaction >
<ejb-name>CommandEngine</ejb-name>
<method-name>*</method-name>
<trans-attribute>Required</trans-attribute>
</container-transaction>
...
And the entity beans all have similar settings .....
Am I being really dumb?
Kev -
4. Re: Transaction scope with Session beans, flat classes and E
adrian.brock Jul 8, 2003 8:50 AM (in response to krichards)Only RuntimeException, Error and RemoteException force
a rollback, you must setRollBackOnly() on the bean context
if you want other Exceptions to rollback the transaction.
Regards,
Adrian -
5. Re: Transaction scope with Session beans, flat classes and E
krichards Jul 8, 2003 9:12 AM (in response to krichards)Thanks I just figured that out!!! So the correct answer was of course -- yes you are being dumb!!
Thanks all
Kev