views:

19

answers:

1

I've got following java class.

package com.org.data.dbresource;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

public class DBConnectionManager {
    private SqlMapClientTemplate sqlMapClientTemplate;

    public void setSqlMapClientTemplate (SqlMapClientTemplate sq)
    {
        this.sqlMapClientTemplate = sq;
    }   

    public SqlMapClientTemplate getSqlMapClientTemplate ()
    {
        return this.sqlMapClientTemplate;
    }
}

My Spring xml looks like following:

 <bean id="IbatisDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/RSRC/app/oltp"/>
 </bean>

 <bean id="MySqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
  <property name="configLocation" value="classpath:sql-map.xml"/>
  <property name="dataSource" ref="IbatisDataSource"/>
 </bean>

 <bean id="myObject" class="com.org.data.dbresource.DBConnectionManager">
    <property name="sqlMapClientTemplate" ref="MySqlMapClient"/>
 </bean>

Error I get is:

Failed to convert property value of type [com.ibatis.sqlmap.engine.impl.SqlMapClientImpl] to required type [org.springframework.orm.ibatis.SqlMapClientTemplate] for property 'sqlMapClientTemplate';

Everything works fine if, instead of SqlMapClientTemplate I pass SqlMapClient but then I have to explicitly catch SQLExceptions

What should I change?

A: 

The error says it all - you're trying to inject an object of type SqlMapClient (as created by SqlMapClientFactoryBean) into a property of type SqlMapClientTemplate.

You need to manually instantiate the SqlMapClientTemplate yourself, either inside DBConnectionManager, e.g.

private SqlMapClientTemplate sqlMapClientTemplate;

public void setSqlMapClient(SqlMapClient sqlMapClient)
{
    this.sqlMapClientTemplate = new SqlMapClientTemplate(sqlMapClient);
}   

and then

<bean id="myObject" class="com.org.data.dbresource.DBConnectionManager">
   <property name="sqlMapClient" ref="MySqlMapClient"/>
</bean>

Remember, SqlMapClientTemplate isw nothing more than a helper class. Neither Spring nor iBatis mandates its use, and if you want to use it, you need to instantiate it yourself.

skaffman
that is spot on. have you worked with spring before ...how do you possess such knowledge :)
learn_plsql
@learn_plsql: I've had a play with it here or there :)
skaffman