View Full Version : DBCP + IBATIS inserts do not work
davidr
Sep 13th, 2004, 04:11 AM
Is anyone out there using IBATIS + DBCP (I am using with an oracle 9 database).
When i use Spring to define my DBCP datasource, inserts do not show up in the database, though it is accessing the database and i can get oracle errors if i violate a primary key on the insert. My workaround has been to not define a datasource in Spring and set it in Ibatis sqlconfig file and then it works fine.
I am not sure how to track down what could be causing this problem as i have no errors.
And in spring if I use the DriverManagerDataSource or JNDI the inserts do work.
Any help would be appreciated.
Thanks,
David
dwsmith75
Sep 13th, 2004, 07:44 AM
Off the top of my head, your probably have auto-commit set to false
Rod Johnson
Sep 13th, 2004, 07:44 AM
Looks like your transactions aren't committing. What transaction management are you using? It could be that it's only working when you have autocommit on...
davidr
Sep 13th, 2004, 07:53 AM
Yes, i assumed the issue was the autocommit. I played with autocommit with no success. I am not using any transaction management as this is a very simple insert I am doing in a Junit test. And when i exchange just the DS to either JNDI or the Spring datasource all is fine
davidr
Sep 14th, 2004, 04:22 AM
Rod, Are there any settings you would recommend that i can play with in DBCP to try to move past this? I really would like to use Spring and not IBATIS for my DataSource.
Thanks,
David
davidr
Nov 11th, 2004, 08:25 AM
Rod,
I have made a small example to show my problem:
Here is the table:
CREATE TABLE tgr.dummy
(data VARCHAR2(50))
here is the sqlmap insert:
<insert id="dummy" parameterClass="string">
insert into tgr.dummy
(data)
values
(#value#)
</insert>
and here is the code:
public void insertDummyRequest(String s) {
try {
getSqlMapClient().insert("dummy", s);
}
catch (SQLException ex) {
logger.error("Failed to store request "
+ " Error: " + ex.getMessage());
}
}
Here is my settings in the applicationContext.xml:
<bean id="sqlMap" class="org.springframework.orm.ibatis.SqlMapClientFactory Bean">
<property name="configLocation">
<value>config/sqlconfig.xml</value>
</property>
<property name="dataSource">
<ref local="dbcpDataSource" />
</property>
</bean>
and the configuration of the datasource is:
<bean id="dbcpDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property>
<property name="url"><value>string</value></property>
<property name="username"><value>string</value></property>
<property name="password"><value>string</value></property>
</bean>
if i comment out the line that sets the property of the datasource in the sqlmap and thus it uses the datasource in teh sqlconfig, it works. Alternatively, if i use the DriverManagerDataSource, it works. So, i seems to be some configuration issue of the combination of spring and ibatis and dbcp. I have not seen any clues to this by running in a debugger. Any thoughts?
Thanks,
David
davidr
Nov 22nd, 2004, 07:04 AM
I think I understand the problem. When i use a datasource from Spring, Spring sets as the transaction manager the external transaction manager, which now requires me to set a transaction manager explicitly in my applicationContext. However, now i am just wondering what i need to do in code, to use the transaction manager.
Do i need to explicityly use a transaciton manager? All i am trying to do are simple inserts.
Thanks,
David
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.