Hi Edla,

I am posting my code.
I have 3 Insert statements in the create method of a single Entity bean.

So in the deployment descriptor, i have given the transaction attribute as Required 
for the create method.

Just have a look at the code and tell me where am i going wrong.




    public Integer ejbCreate (ContactInformation info,int referenceId)

        throws CreateException {

        // set the instance data
        this.info = info;

        IndividualDAO IDAO = new IndividualDAO();

        IDAO.setInfo(info);
                try
                {
                  dbConnection = getDBConnection();

                  individualId = IDAO.create(dbConnection,referenceId,context);

                 return (individualId);
                }
        catch (java.sql.SQLException se) {
                        System.out.println("Rolling back");
            throw new EJBException ("SQL Exception in create:" + se);
        } finally {
            try {
                dbConnection.close();
            } catch (SQLException se) {
               throw new EJBException("SQL Exception in create:" + se);
            }
        }


    }



Here comes IDAO's create method:

    public Integer create(Connection con,int referenceId,EntityContext context)
        throws SQLException {

        dbConnection = con;
               insertIndividual(referenceId,context);
                return individualId;
    }




   private void insertIndividual(int referenceId,EntityContext context) throws 
SQLException {



          if ( !isValidData() )
               throw new SQLException ("Illegal data values for insert");
                         //System.out.println("not valid data");


           Statement stmt = dbConnection.createStatement();

                 String queryStr = "INSERT  INTO " + DatabaseNames.NAME_TABLE +
               "(NameId,NameTypeId,FirstName,MiddleName,LastName) "
                + "VALUES (name_id_seq.nextval,"
               + "'" + info.getName().getNameTypeId() + "',"
               + "'" + info.getName().getFirstName().trim() + "',"
               + "'" + info.getName().getMiddleName() .trim() + "',"
               + "'" + info.getName().getLastName() .trim() + "')" ;
        System.out.println(queryStr);

                 int resultCount = stmt.executeUpdate(queryStr);

                  if ( resultCount != 1 )
                       throw new SQLException("ERROR in NAME_TABLE INSERT !! 
resultCount = " +
                                              resultCount);


            queryStr = "INSERT INTO " + DatabaseNames.ADDRESS_X_TABLE +
               
"(addressid,addresstypeid,referenceid,address,city,state,zipcode,country) "
                + "VALUES (address_x_id_seq.nextval,"
                + info.getAddress().getAddressTypeId() + ","
                                + referenceId + ","
               + "'" + info.getAddress().getAddress().trim() + "',"
               + "'" + info.getAddress().getCity().trim() + "',"
               + "'" + info.getAddress().getState().trim() + "',"
               + "'" + info.getAddress().getZipCode().trim() + "',"
               + "'" + info.getAddress().getCountry().trim() +"')";

        System.out.println(queryStr);
           Debug.println("queryString is: "+ queryStr);
            resultCount = stmt.executeUpdate(queryStr);

           if ( resultCount != 1 )
               throw new SQLException("ERROR in ADDRESS_TABLE INSERT !! resultCount = 
" +
                                      resultCount);

                  queryStr = "INSERT INTO " + DatabaseNames.PHONE_X_TABLE +
               "(phoneid,phonetypeid,referenceid,phonenumbber) "
                + "VALUES (phone_x_id_seq.nextval,"
                + info.getPhoneTypeId() + ","
                                + referenceId + ","
               + "'" + info.getTelephone() + "')";
        System.out.println(queryStr);

           Debug.println("queryString is: "+ queryStr);
            resultCount = stmt.executeUpdate(queryStr);

           if ( resultCount != 1 )
               throw new SQLException("ERROR in PHONE_TABLE INSERT !! resultCount = " +
                                      resultCount);

        queryStr = "INSERT INTO " + DatabaseNames.INDIVIDUAL_TABLE +
               "(individualid,nameid,addressid,phoneid,referenceid) "
                + "VALUES 
(individual_id_seq.nextval,name_id_seq.currval,address_x_id_seq.currval,phone_x_id_seq.currval,"
                                + referenceId  + ")";
        System.out.println(queryStr);

           Debug.println("queryString is: "+ queryStr);
            resultCount = stmt.executeUpdate(queryStr);

           if ( resultCount != 1 )
               throw new SQLException("ERROR in INDIVIDUAL_TABLE INSERT !! resultCount 
= " +
                                      resultCount);

    queryStr = "SELECT individual_id_seq.currval from dual" ;
        ResultSet result=null;
         result = stmt.executeQuery(queryStr);
        if (!(result.next()))
        {
           throw new SQLException("UserId not found");
        }
        else
        {
                individualId = new Integer(result.getInt(1));
        }
           stmt.close();


       }



On Thu, 18 January 2001, E Bakka Reddy wrote:

>
> Hi Pooja,
>
> Try to provide more info./expln on u problem, u q is not clear, but  i
> understood it like below
>
> u want map to three tables, three cmp's under single transaction
>
> if i am write, read the following stuff from weblogic
>
> Calling multiple EJBs from a single transaction context
>
> In the following code fragment, a client application obtains a
> UserTransaction object and uses it to begin and commit a transaction. The
> client invokes two EJBs within the context of the transaction. The
> transaction attribute for each EJB has been set to Required:
>
> import javax.transaction.*;
> ...
> u = (UserTransaction)
> jndiContext.lookup("javax.transaction.UserTransaction");
> u.begin();
> account1.withdraw(100);
> account2.deposit(100);
> u.commit();
> ...
> In the above code fragment, updates performed by the "account1" and
> "account2" EJBs occur within the context of a single UserTransaction - they
> commit or roll back as a logical unit. This is true regardless of whether
> "account1" and "account2" reside on the same WebLogic Server, multiple
> WebLogic Servers, or a WebLogic Server cluster.
>
> The only requirement for wrapping EJB calls in this manner is that both
> "account1" and "account2" must support the client transaction - the beans'
> trans-attribute element must be set to Required, Supports, or Mandatory.
>
> Edla B. Reddy
>
>
>
>
> Shelly Aggrawal <[EMAIL PROTECTED]> on 18/01/2001 11:55:38 AM
>
> Please respond to A mailing list for Enterprise JavaBeans development
>       <[EMAIL PROTECTED]>
>
> To:   [EMAIL PROTECTED]
> cc:    (bcc: ebreddy/Cds)
>
> Subject:  Re: Container Managed Transactions in Entity Beans
>
>
>
>
> Is how  ur xml looks. Try doing this.
>
>  <method>
>    <ejb-name>xxx</ejb-name>
>    <method-intf>Home</method-intf>
>    <method-name>create</method-name>
>  </method>
>  <trans-attribute>Required</trans-attribute>
>
> ----- Original Message -----
> From: Pooja Keswani <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, January 18, 2001 11:32 AM
> Subject: Re: Container Managed Transactions in Entity Beans
>
>
> > Hi,
> >
> > I have tried giving the attribute in thexml as u said.
> > But it does not work.
> > If theres is a problem in the second insert, it doesnt rollback the first
> one.
> >
> > pooja
> > On Thu, 18 January 2001, Shelly Aggrawal wrote:
> >
> > >
> > > In the xml file, just specify the method name and the transaction
> attribute.
> > > U do not need to write any code anywhere. By default the transaction
> > > attribute is specified as "Rquired" in the xml file.
> > >
> > >
> > > ----- Original Message -----
> > > From: Pooja Keswani <[EMAIL PROTECTED]>
> > > To: <[EMAIL PROTECTED]>
> > > Sent: Thursday, January 18, 2001 10:33 AM
> > > Subject: Container Managed Transactions in Entity Beans
> > >
> > >
> > > > Hi,
> > > >
> > > > I have an Entity bean and i want Container managed transaction for
> it.
> The
> > > create method of the bean performs 3 SQL Inserts.
> > > >
> > > > How do i go about writing the ejb-jar.xml for it ?
> > > >
> > > > and do i have to write rollback in the catch SQLException of the
> create
> > > method.
> > > >
> > > > Any help will be appreciated.
> > > >
> > > > Thanks
> > > >
> > > > Pooja
> > > >
> > > >
> > > >
> > > > Chequemail.com - a free web based e-mail service that also pays!!!
> > > > http://www.chequemail.com
> > > >
> > > >
> > >
> ===========================================================================
> > > > 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".
> >
> >
> > Chequemail.com - a free web based e-mail service that also pays!!!
> > http://www.chequemail.com
> >
> >
> ===========================================================================
> > 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".
>
> ===========================================================================
> 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".


Chequemail.com - a free web based e-mail service that also pays!!!
http://www.chequemail.com

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