Kumar K Behura wrote:
> I am facing a problem with the rollback issues of
> container managed entity beans. I have a session bean
> which contains the references of two entity beans
> representing two tables(viz. Employee and Department).
> What I need to have is the transaction includes a
> department creation followed by an employee creation.
Are you doing both creation operations within a single method call on the
session bean? Or are you planning to do this with two seperate method calls
on the session bean?
If the latter, first of all I'd recommend modifying the interface so that
you do it all in one call. The main reason for this is that if you spread
it across two calls, you have no choice here but to start the transaction in
one call and commit it in the second - this kind of thing is to be avoided
if possible, since you want your transaction times as short as possible.
Opening up the possibility that someone might call one method, starting the
transaction, and never call the second means that the transaction will last
until it times out, which really isn't good.
But if you do decide to go down this route, you need to be aware that the
container won't make transactions span method calls by default.
Container-managed transactions only last for the duration of a single method
call unless your bean happens to be part of a larger transaction scope, in
which case the transaction's life will be determined by the bean at the root
of the transaction scope. So you would need to specify bean-managed
transactions for your bean, then you'll need to start the transaction
explicitly in the first method, then commit it in the second.
(As an alternative you could start a user transaction in your client - this
would make the client code the root of the transaction scope, not your bean,
so the client code could force the transaction to span both methods. But
this seems like pretty bad design to me - making a bean that will only work
if the user defines a transaction and makes it span two method calls.
Better to design a bean where the client isn't given the option to use it
incorrectly.)
> Whenever any of the two create fails I need the whole
> transaction to be rolled back. Regarding the transaction
> attributes, I have set the transaction attribute of the
> session bean to TX_REQUIRED and for the entity beans
> TX_SUPPORTS.
Hmm... I usually make entity beans TX_REQUIRED - does it make sense for
them to be anything else? (You'll always be doing data access, typically a
load, which might be followed by a store.)
--
Ian Griffiths
DevelopMentor
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".