Hi Hemant,
I am glad I could be of help. I actually figured this out the hard way.
Regarding Sachin Pandey's question, this configuration I think is purely
weblogic specific. In JBoss you don't have to do fiddle with
DataSources. Also, once the transaction attributes are set in ejb-jar,
you should be fine and the container should roll-back when an unchecked
exception is thrown or during an explicit call to setRollBackOnly().
Regarding Ashwani's question, this configuration is available in
weblogic console at "Services>JDBC".
-karthik
Hemant Arora wrote:
> Hi Karthik
>
> It works fine when i made the datasource as TXDataSource in Weblogic
>
> For your info I'm using weblogic 5.1
>
> Thanks a Lot for the Help
>
> Regards
>
> Hemant
>
> Karthikeyan M <[EMAIL PROTECTED]>
> Sent by: A mailing list for Enterprise JavaBeans development
> <[EMAIL PROTECTED]>
> 06/19/2002 04:22 PM MST
> Please respond to Karthikeyan M
>
> To: [EMAIL PROTECTED]
> cc:
> bcc:
> Subject: Re: Transaction in SFSB
>
>
>
> Hi,
>
> Did you make sure you have configured weblogic to use TxDataSource
> instead of
> normal DataSource for the obtaining db connections. If you are using
> just
> DataSource for obtaining connections, weblogic runs in auto-commit
> mode.
>
> -karthik.
>
> Ashwani Kalra wrote:
>
> > hi,
> > I checked at my db. The autocommit feature is off. It works only
> when In my
> > session bean I write connection.setAutocommit(false).
> > Why is this happening ??
> >
> > Ashwani
> >
> > ----- Original Message -----
> > From: "Ashwani Kalra" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Wednesday, June 19, 2002 5:36 PM
> > Subject: Re: Transaction in SFSB
> >
> > > Hi,
> > > I tried your scenario. I used connection.setAutocommit(false) in
> my code
> > and
> > > it works fine. It means at the db end autocommit feature should be
> off.
> > If
> > > I dont use connection.setAutocommit(false) then in catch block
> even if I
> > do
> > > Context.setRollbackOnly() , it doesnt work.
> > >
> > > Ashwani
> > >
> > > ----- Original Message -----
> > > From: "Hemant Arora" <[EMAIL PROTECTED]>
> > > To: <[EMAIL PROTECTED]>
> > > Sent: Wednesday, June 19, 2002 1:46 PM
> > > Subject: Transaction in SFSB
> > >
> > >
> > > > Hi Ashwin
> > > >
> > > > Sorry for yesterday's mail.
> > > >
> > > > Actually I forgot to write some details of the transactions in
> my code
> > > >
> > > > Please find the latest code
> > > >
> > > > I do not have the "Account" table in my database
> > > >
> > > > so when I try to inseret the 2 queries
> > > >
> > > > then the second one should fail as its happening and the first
> insert
> > > > should rollback as there is
> > > >
> > > > Sql exception in the second query
> > > >
> > > > The weblogic console shows this error which is correct as per my
>
> > > > understanding
> > > >
> > > > Wed Jun 19 12:42:35 GMT+05:30 2002:<I> <EJB JAR deployment
> > > > d:/weblogic/myserver/romanCount.jar> Transaction:
> '1024470662649_3'
> > rolled
> > > > back due to EJB excep
> > > > tion:
> > > > java.rmi.RemoteException: ORA-00942: table or view does not
> exist
> > > > at
> > > >
> > >
> >
> com.wiley.compBooks.roman.session.Count.CountBean.dbconnection(CountBean.jav
>
> > > a:88)
> > > > at
> > > >
> > >
> >
> com.wiley.compBooks.roman.session.Count.CountBeanEOImpl.dbconnection(CountBe
>
> > > anEOImpl.java:148)
> > > > at
> > > >
> > >
> >
> com.wiley.compBooks.roman.session.Count.CountBeanEOImpl_WLSkel.invoke(CountB
>
> > > eanEOImpl_WLSkel.java:83)
> > > > at
> > > >
> > >
> >
> weblogic.rmi.extensions.BasicServerObjectAdapter.invoke(BasicServerObjectAda
>
> > > pter.java:338)
> > > > at
> > > >
> > >
> >
> weblogic.rmi.extensions.BasicRequestHandler.handleRequest(BasicRequestHandle
>
> > > r.java:69)
> > > > at
> > > >
> > >
> >
> weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:1
>
> > > 5)
> > > > at
> weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
> > > >
> > > >
> > > > but when i see the database table "Accounts" The record does
> exists , it
> > > > should have been rolled back
> > > >
> > > > Any help
> > > >
> > > > Regards
> > > > Hemant
> > > >
> > > >
> > > > package com.wiley.compBooks.roman.session.Count;
> > > >
> > > > import javax.ejb.*;
> > > > import java.sql.Connection;
> > > > import java.sql.PreparedStatement;
> > > > import java.sql.ResultSet;
> > > > import java.sql.SQLException;
> > > > import java.sql.*;
> > > > import javax.naming.NamingException;
> > > > import javax.naming.InitialContext;
> > > > import javax.transaction.UserTransaction;
> > > > import javax.sql.DataSource;
> > > > import java.rmi.RemoteException;
> > > > import java.io.*;
> > > >
> > > > /**
> > > > * Demonstration Stateful Session Bean. This Bean is
> initialized
> > > > * to some integer value, and has a business method which
> > > > * increments the value.
> > > > *
> > > > * This example shows the basics of how to write a stateful
> > > > * session bean, and how passivation/activation works.
> > > > */
> > > > public class CountBean implements SessionBean{
> > > >
> > > > SessionContext ctx;
> > > > // The current counter is our conversational state.
> > > > public int val;
> > > >
> > > > //
> > > > // Business methods
> > > > //
> > > >
> > > > /**
> > > > * Counts up
> > > > */
> > > > public int count() {
> > > > System.out.println("count()");
> > > > return ++val;
> > > > }
> > > >
> > > > /**
> > > > * Counts up
> > > > */
> > > > public String dbconnection() throws
> RemoteException,SQLException
> > > > {
> > > > InitialContext initCtx = null;
> > > > DataSource ds = null;
> > > > System.out.println("INSIDE dbconnection");
> > > > String strGotit = ""
> > > > Connection con = null;
> > > > PreparedStatement stmt = null;
> > > > PreparedStatement stmt1 = null;
> > > >
> > > > try
> > > > {
> > > >
> > > > initCtx = new InitialContext();
> > > > ds = (javax.sql.DataSource)
> > > > initCtx.lookup("oraclePool");
> > > > con = ds.getConnection();
> > > >
> > > > stmt = con.prepareStatement("insert into
> accounts
> > > > (id,name,balance) values(?,?,?) ");
> > > >
> > > > stmt.setInt(1,1);
> > > > stmt.setString(2,"Tester 1");
> > > > stmt.setInt(3,1212);
> > > >
> > > > if(stmt.executeUpdate() != 1){
> > > > throw new RemoteException("Insert
> Failed");
> > > > }
> > > >
> > > > stmt1 = con.prepareStatement("insert into account
> > > > (id,name,balance) values(?,?,?) ");
> > > >
> > > > stmt1.setInt(1,2);
> > > > stmt1.setString(2,"Tester 2");
> > > > stmt1.setInt(3,1212);
> > > >
> > > > if(stmt1.executeUpdate() != 1){
> > > > throw new RemoteException("Insert
> Failed");
> > > > }
> > > >
> > > >
> > > > }catch(javax.naming.NamingException ne){
> > > > throw new EJBException(ne);
> > > > }catch(SQLException sqe)
> > > > {
> > > > throw new RemoteException(sqe.getMessage());
> > > > }
> > > > finally
> > > > {
> > > > try
> > > > {
> > > > stmt.close();
> > > > stmt1.close();
> > > > con.close();
> > > >
> > > > if(initCtx != null)
> > > > initCtx.close();
> > > > file://return ds.getConnection();
> > > > }
> > > > catch(NamingException ne)
> > > > {
> > > > file://log("Error closing context: " + ne);
> > > > throw new EJBException(ne);
> > > > }
> > > > }
> > > >
> > > > return strGotit;
> > > > }
> > > >
> > > > //
> > > > // EJB-required methods
> > > > //
> > > >
> > > > public void ejbCreate(int val) throws CreateException {
> > > > this.val = val;
> > > > System.out.println("ejbCreate()");
> > > > }
> > > >
> > > > public void ejbRemove() {
> > > > System.out.println("ejbRemove()");
> > > > }
> > > >
> > > > public void ejbActivate() {
> > > > System.out.println("ejbActivate()");
> > > > }
> > > >
> > > > public void ejbPassivate() {
> > > > System.out.println("ejbPassivate()");
> > > > }
> > > >
> > > > public void setSessionContext(SessionContext ctx) {
> > > > }
> > > > }
> > > >
> > > > -----------------------Disclaimer------------------------
> > > >
> > > > The views of the author may not necessarily reflect those
> > > > of the Company. All liability is excluded to the extent
> > > > permitted by law for any claims arising as a result of the
> > > > use of this medium to transmit information by or to
> > > > IT Solutions (India) Pvt. Ltd.
> > > >
> > > > We have taken precautions to minimize the risk of
> > > > transmitting software viruses, but we advise you to
> > > > carry out your own virus checks on any attachment to
> > > > this message. We cannot accept liability for any loss or
> > > > damage caused by software viruses.
> > > >
> > > > ------------------------Disclaimer------------------------
> > > >
> > > >
> > >
> >
> ===========================================================================
>
> > > > 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".
>
> ===========================================================================
>
> 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".