hi  Collins,

i have written following code for transaction management in the stateless
session bean.
itz working fine.
I am throwing an exception in the entity bean(PLZ REFER TO THE CODE GIVEN
BELOW)

rollback & commit is happening properly based on excepotion in the entity
bean(cmp).
is this the   proper way of maintaining transaction in ejb??

i also tried by specifing in the DD. but container is not managing
transaction implicitly. i am working on Weblogic 5.1 on solaris??
plz gimme suggestion regarding this.

public boolean setUserInfoSl(UserInfoSl upDtObj)
        {
                try{
                this.userID = upDtObj.userID;
                this.firstName = upDtObj.firstName;
                this.middleName= upDtObj.middleName;;
                this.lastName=upDtObj.lastName;
                this.password=upDtObj.password;
                this.comments=upDtObj.comments;
                this.priceLimit=upDtObj.priceLimit;
                this.aspCustID=upDtObj.aspCustID;
                this.contactID=upDtObj.contactID;

                this.userLastModifiedTimestamp = getCurrentTimestamp();
                throw new Exception();
                //return true;
                }
                catch(Exception e)
                {
                        return false;
                }
        }





       import javax.transaction.UserTransaction;
       import javax.transaction.SystemException;
       import javax.transaction.HeuristicMixedException;
       import javax.transaction.HeuristicRollbackException;
       import javax.transaction.NotSupportedException;
       import javax.transaction.RollbackException;


public class UserInfoSessionBean implements SessionBean
{

                      public boolean updateUserDetails(UserInfoSl
updateInfoObj) throws UserInfoException
        {
                try
                {

                        System.out.println("home found************");
                        Context ctx = getInitialContext();
                        tx =
(UserTransaction)ctx.lookup("java:comp/UserTransaction");
                        tx.begin();

                        UserInfoPK pk = new UserInfoPK();
                        pk.userID = updateInfoObj.userID;
                        UserInfoEntityRemote upDateDet =
getUserEntityHome().findByPrimaryKey(pk);
                        if
(upDateDet.getUserLastModifiedTimestamp().equals(updateInfoObj.userLastModif
iedTimestamp))
                        {
                                boolean gotException =
upDateDet.setUserInfoSl(updateInfoObj);
                                System.out.println("JJJJJJJJJJJJJJJJJJJJJ
"+gotException);
                                if(!gotException)
                                {
                                        try
                                        {
                                                tx.rollback();

System.out.println("%%%%%%%rolled backwwwwwwwwwwwwwwwwwwwwwww");
                                        }
                                                catch(Exception e)
                                        {
                                        }
                                }
                                else
                                {
                                        tx.commit();

System.out.println("%%%%%%%committed");
                                        return true;
                                }
                                //throw new Exception();

                        }
                        else
                        {
                                return false;
                        }
                        //return true;
                }
                catch(javax.ejb.ObjectNotFoundException oe)
                {
                        throw new UserInfoException("User id does not
exist");
                        //return false;
                }
                catch(java.rmi.RemoteException re)
                {
                        re.printStackTrace();
                }
                catch(Throwable t)
                {
                        t.printStackTrace();
                }

                return false;
        }




With regards
Purushotham Das

> -----Original Message-----
> From: John Collins [SMTP:[EMAIL PROTECTED]]
> Sent: Sunday, July 23, 2000 11:04 AM
> To:   [EMAIL PROTECTED]
> Subject:      Re: Transaction commit/rolback for stateful session beans
>
> "Kenneth D. Litwak" wrote:
>
> >    This is what I thought.  Transactions for session beans are really
> pretty
> > meaningless, since no matter wwhat, the bean developer has to do all the
> work.
> > A Ts that is CMT is only of real value for an entity bean.
>
> Not true.  It's true that there's no automatic rollback for session bean
> state,
> but there is for entity bean state for any entity beans whose methods are
> within
> the scope of the CMT.  See my response on the thread "Transaction, entity
> beans
> and passivation".
>
> From a design standpoint, it seems almost pointless to control
> transactions at
> the level of individual entity bean methods.  What you want more typically
> is to
> have some session bean that needs to make a consistent set of changes to a
> number
> of entities.  That's the method that needs the Requires (or Requires-new)
> attribute.  You can put a Supports attribute on the entity bean methods.
>
> John Collins
>
> ==========================================================================
> =
> 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".

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