Announcement Announcement Module
Collapse
No announcement yet.
help with SqlMapClientTemplate for Ibatis Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • help with SqlMapClientTemplate for Ibatis

    Hi,
    We are using IBatis to implement persistence and trying to use SqlMapClientTemplate for getting to IBatis API.

    I am running into a problem in instantiating SqlMapClientTemplate correctly. We are creating an instance of SqlMapClientFactoryBean where we set the configurationLocation and the Datasource. Now I want to be able to pass sqlMapClient to the SqlMapClientTemplate instance so that it can pickup the configuration file correctly. However, we cannot pass the instance created from SqlMapClientFactoryBean to sqlMapClientTemplate since this is of type com.ibatis.sqlmap.engine.impl.SqlMapClientImpl where as sqlMapClientTemplate expects type com.ibatis.sqlmap.client.sqlMapClient..

    I tried to see if I could build the sqlMapClient from the sqlMapClientFactoryBean myself, but I don't have that method available to me..

    Question is how do you implement using SqlMapClientTemplate - are there any examples anywhere (I've only seen examples with SqlMapClientDAOSupport which we cannot use because it needs to be extended and we need to extend another class that abstracts our dao instantiation, so we don't have to change code if we want to change the implementation from Ibatis to Hibernate..

    so our design looks like:
    Code:
    public interface ICustomerDAO { 
    ..}
    
    public abstract class CustomerDAO implements ICustomerDAO { //this is the class that will be used in the rest of the application - this will be injected using spring.
    ..
    }
    
    public class IBatisSqlMapCustomerDAO extends CustomerDAO {
            private SqlMapClientTemplate sqlMapClientTemplate ;
            
            public void setSqlMapClientTemplate(sqlMapClientTemplate sqlMapClientTemplate) {
                  this.sqlMapClientTemplate = sqlMapClientTemplate;
    
           }
          ...
    }



    Here's my configuration file:
    Code:
    	<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    		<property name="configLocation" value="sql-map-config.xml"/>
    		<property name="dataSource" ref="dataSource"/>
    	</bean>
    	
    	<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
    		<property name="sqlMapClient" ref="sqlMapClient" />
    	</bean>
    	
    	<bean id="customerDAO" class="dao.IBatisSqlMapCustomerDAO">
    		<property name="sqlMapClientTemplate" ref="sqlMapClientTemplate"/>
    	</bean>
    Here's the error I get when I run this:
    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerDAO' defined in class path resource [com/exit41/orderperfect/customeridentification/conf/core.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
    PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.ibatis.sqlmap.engine.impl.SqlMapClientImpl] to required type [org.springframework.orm.ibatis.SqlMapClientTemplate] for property 'sqlMapClient'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [com.ibatis.sqlmap.engine.impl.SqlMapClientImpl] to required type [org.springframework.orm.ibatis.SqlMapClientTemplate] for property 'sqlMapClient': no matching editors or conversion strategy found
    Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessException details (1) are:
    PropertyAccessException 1:
    org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.ibatis.sqlmap.engine.impl.SqlMapClientImpl] to required type [org.springframework.orm.ibatis.SqlMapClientTemplate] for property 'sqlMapClient'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [com.ibatis.sqlmap.engine.impl.SqlMapClientImpl] to required type [org.springframework.orm.ibatis.SqlMapClientTemplate] for property 'sqlMapClient': no matching editors or conversion strategy found
    Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [com.ibatis.sqlmap.engine.impl.SqlMapClientImpl] to required type [org.springframework.orm.ibatis.SqlMapClientTemplate] for property 'sqlMapClient': no matching editors or conversion strategy found
    	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231)
    	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:815)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:645)
    	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
    	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1127)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:862)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:424)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:287)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    	at org.springframework.test.AbstractSingleSpringContextTests.createApplicationContext(AbstractSingleSpringContextTests.java:199)
    	at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:179)
    	at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:158)
    	at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:105)
    	at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:87)
    	at junit.framework.TestCase.runBare(TestCase.java:125)
    	at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Any guideness? - at least pointers to examples of sqlMapClientTemplate implementations?

    Thanks!
    Dipita

  • #2
    Hi all,
    I've found the solution to my problem - my configuration files and code was correct. I was just calling a different configuration files that didn't have my latest files (what a dumb mistake!)

    In anycase, looks like you can pass the instance of SqlMapClientFactoryBean to SqlMapClientTemplate

    Thanks!
    Dipita

    Comment

    Working...
    X