Results 1 to 7 of 7

Thread: DBCP + IBATIS inserts do not work

  1. #1
    Join Date
    Sep 2004
    Posts
    20

    Default DBCP + IBATIS inserts do not work

    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

  2. #2
    Join Date
    Aug 2004
    Location
    Athens, GA
    Posts
    20

    Default

    Off the top of my head, your probably have auto-commit set to false

  3. #3
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    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...
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  4. #4
    Join Date
    Sep 2004
    Posts
    20

    Default

    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

  5. #5
    Join Date
    Sep 2004
    Posts
    20

    Default

    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

  6. #6
    Join Date
    Sep 2004
    Posts
    20

    Default try again with small sample

    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.SqlMapClient FactoryBean">
    <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.O racleDriver</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

  7. #7
    Join Date
    Sep 2004
    Posts
    20

    Default

    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

Similar Threads

  1. iBatis lazy load transaction issues.
    By efpiva in forum Data
    Replies: 3
    Last Post: Jun 22nd, 2005, 06:20 PM
  2. Replies: 6
    Last Post: May 25th, 2005, 01:56 AM
  3. Utilize Spring's JDBC Framework or iBATIS
    By jaybytez in forum Data
    Replies: 2
    Last Post: Mar 11th, 2005, 06:24 PM
  4. Replies: 2
    Last Post: Nov 9th, 2004, 12:13 PM
  5. Replies: 2
    Last Post: Oct 8th, 2004, 08:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •