-
1. Re: Autocommit SQLException
lee_yuki2000 Jun 17, 2003 12:16 AM (in response to cromantm)Are you using EJB? If yes, are you using CMP or BMP? Where did u set your auto commit?
-
2. Re: Autocommit SQLException
cromantm Jun 17, 2003 10:53 AM (in response to cromantm)Yes, I'm using EJB with CMP.
The autocommit is set within the Bean code.
A class within the bean package makes the call to
org.jboss.resource.adapter.jdbc.local.LocalConnection.setAutoCommit(false)
The method is as follows:
Note: The Connection is object from a DataSource object.
static void insertObject(Connection conn, String objectId, Object obj) throws Exception {
boolean autocommit = conn.getAutoCommit();
Log.debug("Saving Blob for objectID:"+objectId);
conn.setAutoCommit(false); // this is where it breaks
try {
insertBlob(conn,objectId,obj);
conn.commit();
} catch(Exception e) {
conn.rollback();
throw(e);
} finally {
conn.setAutoCommit(autocommit);
}
} -
3. Re: Autocommit SQLException
cromantm Jun 17, 2003 11:22 AM (in response to cromantm)A bit more info....
ejb-jar.xml
-----------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar id="ejb-jar_ID">
<enterprise-beans>
<ejb-name>TaskPersistenceEJB</ejb-name>
com.ejb.TaskPersistenceHome
com.ejb.TaskPersistence
<ejb-class>com.ejb.TaskPersistenceBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry id="EnvEntry_1">
Flag to use db persistence
<env-entry-name>USE_DB_PERSISTENCE</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>0</env-entry-value>
</env-entry>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
Transaction attributes for 'TaskPersistenceEJB' methods
<ejb-name>TaskPersistenceEJB</ejb-name>
<method-name>*</method-name>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
------------------------------------------
jboss.xml
------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<enterprise-beans>
<ejb-name>TaskPersistenceEJB</ejb-name>
<jndi-name>task/persist</jndi-name>
</enterprise-beans> -
4. Re: Autocommit SQLException
lee_yuki2000 Jun 17, 2003 11:28 PM (in response to cromantm)If you are manually setting the auto commit to false, you should use BMP instead of CMP. If you want to use CMP, the auto commit is automatically set to true. This mean when you are using CMP, you don't need to execute commit statement.
I have the same error like yours and when i modify to BMP, everything works fine. In your ejb-jar.xml, change to bean.
<transaction-type>Bean</transaction-type> -
5. Re: Autocommit SQLException
cromantm Jun 18, 2003 5:45 PM (in response to cromantm)
Found another solution as well. Decided to use the NoTxConnectionManager for the DataSource configured instead of LocalTxConnectionManager. This allowed me to have control over the transaction.
I will try your approach as well. It may be best to change to BMP.
Thanks