Announcement Announcement Module
Collapse
No announcement yet.
sqlMap not writable exception when upgrading to sqlMaps 2 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • sqlMap not writable exception when upgrading to sqlMaps 2

    I'm trying to upgrade to use sqlMaps 2. I changed my config files to use the new iBatis DTDs, and changed code to implement the new 'client' interfaces. However, I'm still doing something wrong as I'm getting an error saying the sqlMap property is not writable. I know this exception is common and I've had it happen in the past when I don't have a setter method in a particular bean. My ibatis DAO implementation class in fact does not have a sqlMap property, but I don't think it needs one, does it? It didn't before (under sqlMaps 1.3).

    One thing that seems strange to me is that my sqlMap xml file choked when I tried to supply the attribute id="Workspace". From iBatis docs, it looks like I should supply this, but the DTD says otherwise so I left it off. I wonder if that could be related to the problem?

    Anyway, here's some code snippets and the exception. I'm hoping someone can see the simple mistake I'm missing here.

    Thanks in advance,
    Mike

    **In my Spring config file**
    ..
    ..

    <bean id="sqlMap"
    class="org.springframework.orm.ibatis.SqlMapClient FactoryBean">
    <property name="configLocation"><value>WEB-INF/sql-map-config.xml</value></property>
    </bean>

    <bean id="workspaceDao"
    class="dao.ibatis.SqlMapWorkspaceDao">
    <property name="dataSource"><ref local="dataSource"/></property>
    <property name="sqlMap"><ref local="sqlMap"/></property>
    </bean>



    **In my sqlMapConfig file**


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sqlMapConfig
    PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-config-2.dtd">

    <sqlMapConfig>
    <sqlMap resource="dao/ibatis/maps/Workspace.xml"/>
    </sqlMapConfig>



    **In my Workspace.xml sqlMap file**

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sqlMap
    PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-2.dtd">

    <sqlMap>

    <resultMap id="result" class="domain.Workspace">
    ..
    ..
    </resultMap>

    <statement id="getWorkspaceById" resultMap="result">
    ..
    ..
    </statement>

    </sqlMap>


    **in dao.ibatis.SqlMapWorkspaceDao.java**


    import org.springframework.dao.DataAccessException;
    import org.springframework.orm.ibatis.support.SqlMapClien tDaoSupport;
    import dao.WorkspaceDao;
    import domain.Workspace;

    public class SqlMapWorkspaceDao extends SqlMapClientDaoSupport implements WorkspaceDao {

    public Workspace getWorkspaceById(Integer workspaceId) throws DataAccessException {
    return (Workspace) getSqlMapClientTemplate().queryForObject("getWorks paceById", workspaceId);
    }

    //(there is no sqlMap property in this file, do I need one?)
    }


    junit.framework.AssertionFailedError: Exception in constructor: testGetWorkspaceById (org.springframework.beans.factory.BeanCreationExc eption: Error creating bean with name 'workspaceDao' defined in class path resource [WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'sqlMap' of bean class [dao.ibatis.SqlMapWorkspaceDao]: Property 'sqlMap' is not writable
    org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'sqlMap' of bean class [dao.ibatis.SqlMapWorkspaceDao]: Property 'sqlMap' is not writable
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:630)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:568)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:685)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:712)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:701)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:626)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:467)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:232)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:177)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:159)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:183)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:268)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:68)
    at dao.BaseDAOTestCase.<init>(BaseDAOTestCase.java:26 )
    at dao.WorkspaceDAOTest.<init>(WorkspaceDAOTest.java: 15)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Construc tor.java:274)
    )
    0.010

  • #2
    You are now inheriting from SqlMapClientDaoSupport, which has a property called sqlMapClient, where the old SqlMapDaoSupport you were using took a property called sqlMap.

    So you need to change the property name you are using to try to feed in the result of your SqlMapClientFactoryBean into your dao.

    Comment

    Working...
    X