Hey

Jayadeva Babu Gali wrote:
> I have a question related to EJB  and Transactions. I wrote two  Entity
> ( Container Managed ) beans each  will create a row in two separate
> tables of a same pool.Its necessary to create two rows at the same time
> with different tables  otherwise it will become inconsistent.
>
> For this requirement is it necessary to  use
> javax.transaction.Transaction class ? it the servlet (  which calls two
> EJBs ).
>
> I wrote the servlet like this.
<snip>

This would seem like a great place to have a Stateless SessionBean
instead. Create a bean that has the following method (or similar):
public void createOrder()
  throws SomeException
{
  ..lookup and create order..
  ..lookup and create payment..
}
Make the bean TX_REQUIRED.
If the method returns successfully the tx has committed, or if an
exception has been thrown then it rolled back.

An Other way to do it is to have the create in order do a create on
payment. It will probably work, and you don't have to make a new session
bean, but since this is business logic that is really external to
Order's (IMHO) you should use the session bean approach instead.

In general I think it is wise to use the declarative use of
transactions, since it simplifies coding immensely. And we all know that
simpler coding=less bugs->happier life. :-)

HTH :-)

/Rickard

--
Rickard �berg

@home: +46 13 177937
Email: [EMAIL PROTECTED]
Homepage: http://www-und.ida.liu.se/~ricob684

===========================================================================
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".

Reply via email to