Hi I havent yet got a reply to my query as mentioned below in the mail. I am not able yo proceed with the work because of this. My application works witout any problem in J2EE & Oracle 9iAS
Could you pls help Regards Rajesh -----Original Message----- From: rajeshnn Sent: Thursday, September 25, 2003 3:44 PM To: [EMAIL PROTECTED] Subject: RE: [JBoss-user] error while trying to open a new connection Hi Adrian We are providing you the sample code . It contains a servlet and a stateful session bean. In the ejbCreate we are creating a connection and we are setting autoCommit to false at that time. The servlet creates the bean and will call the doQuery() method. At this point the autoCommit attribute is coming as true. We are using bean managed persistence. we have set the attribute SpecCompliant as true in transaction-service.xml. Why is this happening and how can we solve the issue? The example code is attached along with this. Regards Rajesh -----Original Message----- From: Adrian Brock [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 24, 2003 6:30 PM To: [EMAIL PROTECTED] Subject: RE: [JBoss-user] error while trying to open a new connection Again you'll have to give me some information. Where is getConnection() invoked and where do you store the connection? What is done between getting the connection and the commit()? Is this a StatefulSessionBean? What is the deployment descriptor for the resource-ref? What does the following return just before the commit(): m_dbCon.getAutoCommit(); ((org.jboss.resource.adapter.jdbc.WrappedConnection) m_dbCon).getUnderylingConnection().getAutoCommit(); You know this kind of pattern won't scale. You are not using the pool. You will need one db connection per user. Regards, Adrian On Wed, 2003-09-24 at 07:48, rajeshnn wrote: > Hi Adrian > Thanks you very much for the quick response. > > The issue described in the earlier mail(below) has been solved while using > jboss-3.2.2RC4 ( latest jboss release ), as advised by you. > Now i am facing a new error. > > java.sql.SQLException: You cannot commit with autocommit set! > > I had also set CachedConnectionManager in transaction-service.xml( > SpecCompliant to true ) ), > > code is given below: > =============== > public Connection getConnection(){ > String m_strDefaultDataSource ="java:comp/env/jdbc/Data"; > > InitialContext ic = new InitialContext(); > DataSource m_dsCommmon = ( DataSource ) ic.lookup( m_strDefaultDataSource ); > m_dbCon = m_dsCommmon.getConnection(); > m_dbCon.setAutoCommit(false); > > return m_dbCon; > } > > private boolean storeSignInDetails(String strUserName,String strClientIp , > Connection m_dbCon){ > > String strUserId = getUserId(); > strUserId = ( null == strUserId )?"Invalid":strUserId; > > String strQuery ="//sql statement for logging // > try{ > Statement stmt = m_dbCon.createStatement(); > int iCount = stmt.executeUpdate(strQuery); > m_dbCon.commit(); > > }catch(Exception e){ > e.printStackTrace(); > return false; > } > > return true; > > } > > // Also pls note that i am not closing the connection, as this is used for further > transaction. > // We are using bean managed transaction . We are handling the transaction using > JDBC only (not using JavaTransaction API). > //Initially after successful logging of the user, the user details are logged and it > is commited > ( Given in the above function --storeSignInDetails () ). > //Later it is commited , only when the user finishes his transaction. > // So we need to use setAutoCommit( false ); > > Is there any way to prevent this issue.... > > Also can u please clarify as to what JBoss is expecting. Do we need to disable > CachedConnectionManager?? > > > 10:45:37,843 ERROR [STDERR] java.sql.SQLException: You cannot commit with autocommit > set! > 10:45:37,859 ERROR [STDERR] at > org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcCommit > BaseWrapperManagedConnection.java:494) > 10:45:37,859 ERROR [STDERR] at > org.jboss.resource.adapter.jdbc.WrappedConnection.commit(WrappedConnection.java:465) > 10:45:37,859 ERROR [STDERR] at > com.suntec.tbms3.ui.CUserValidateSB.storeSignInDetails(CUserValidateSB.java:318) > > This electronic mail (including any attachment thereto) may be confidential and privileged and is intended only for the individual or entity named above. Any unauthorized use, printing, copying, disclosure or dissemination of this communication may be subject to legal restriction or sanction. Accordingly, if you are not the intended recipient, please notify the sender by replying to this email immediately and delete this email (and any attachment thereto) from your computer system...Thank You This electronic mail (including any attachment thereto) may be confidential and privileged and is intended only for the individual or entity named above. Any unauthorized use, printing, copying, disclosure or dissemination of this communication may be subject to legal restriction or sanction. Accordingly, if you are not the intended recipient, please notify the sender by replying to this email immediately and delete this email (and any attachment thereto) from your computer system...Thank You
/* * Created on Sep 22, 2003 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package com.study; import java.rmi.RemoteException; import javax.ejb.CreateException; import javax.ejb.EJBException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import javax.naming.InitialContext; import javax.sql.*; import java.sql.*; /** * @author krishnakumar * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments * @ejb.bean name = "Query" * display-name = "QueryBean" * description = "Test bean for JBoss" * view-type = "remote" * jndi-name = "ejb/Query" * transaction-type = "Bean" * type = "Stateful" * * @ejb.resource-ref res-ref-name = "jdbc/Data" * res-auth = "Container" * res-type = "javax.sql.DataSource" * jndi-name = "jdbc/Data" * * @ejb.ejb-ref ejb-name = "Help" * * @jboss.ejb-ref-jndi ref-name = "Help" * jndi-name = "ejb/Help" * * * @jboss.resource-ref res-ref-name = "jdbc/Data" * jndi-name = "java:/Data" */ public class QueryBean implements SessionBean { /** * Default create method [EMAIL PROTECTED] CreateException [EMAIL PROTECTED] */ public void ejbCreate() throws CreateException { makeConnection(); try { System.out.println( "After makeConnection AUTO COMMIT is " + m_dbCon.getAutoCommit() ); }catch (SQLException e) { e.printStackTrace(); } } /** * @return * [EMAIL PROTECTED] view-type = "remote" */ public void doQuery() { try{ System.out.println( "Inside doQuery AUTO COMMIT is " + m_dbCon.getAutoCommit() ); }catch (SQLException e) { e.printStackTrace(); } } /* (non-Javadoc) * @see javax.ejb.SessionBean#ejbActivate() */ public void ejbActivate() throws EJBException, RemoteException { // TODO Auto-generated method stub makeConnection(); } /* (non-Javadoc) * @see javax.ejb.SessionBean#ejbPassivate() */ public void ejbPassivate() throws EJBException, RemoteException { // TODO Auto-generated method stub closeConnection(); } /* (non-Javadoc) * @see javax.ejb.SessionBean#ejbRemove() */ public void ejbRemove() throws EJBException, RemoteException { // TODO Auto-generated method stub closeConnection(); } /* (non-Javadoc) * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext) */ public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException { // TODO Auto-generated method stub } private void makeConnection() { try { InitialContext ic = new InitialContext(); m_Ds = ( DataSource ) ic.lookup( "java:comp/env/jdbc/Data" ); m_dbCon = m_Ds.getConnection(); //Setting autocommit to false m_dbCon.setAutoCommit(false); }catch( Exception e) { e.printStackTrace(); } } private void closeConnection() { if( null != m_dbCon ) { try { m_dbCon.close(); }catch( SQLException sqe ) { sqe.printStackTrace(); } } } private Connection m_dbCon; private DataSource m_Ds; }
/* * Created on Sep 22, 2003 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package com.study; import java.io.IOException; import javax.rmi.*; import javax.naming.InitialContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * @author krishnakumar * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments * @web.servlet name = "QueryServlet" * display-name = "QueryServlet" * description = "Test Servlet for JBoss" * * @web.servlet-mapping url-pattern = "/QueryAlias" * * @web.ejb-ref name = "ejb/Query" * type = "Session" * home = "com.study.QueryHome" * remote = "com.study.Query" * description = "Test servlet for JBoss" * * @jboss.ejb-ref-jndi ref-name = "ejb/Query" * jndi-name = "ejb/Query" */ public class QueryServlet extends HttpServlet { Query remote; /* (non-Javadoc) * @see javax.servlet.GenericServlet#init() */ public void init() throws ServletException { // TODO Auto-generated method stub super.init(); try { InitialContext ic = new InitialContext(); Object obj = ic.lookup( "java:comp/env/ejb/Query" ); QueryHome home = (QueryHome)PortableRemoteObject.narrow(obj, QueryHome.class); remote = home.create(); }catch( Exception e ) { e.printStackTrace(); } } /* (non-Javadoc) * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { // TODO Auto-generated method stub doPost(arg0, arg1); } /* (non-Javadoc) * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { // TODO Auto-generated method stub remote.doQuery(); try { remote.remove(); }catch (Exception e) { e.printStackTrace(); } } }