You only defined the typehandler for resultmaps (reads), to make it also work with updates and inserts, you need to:
- define a parameterMap with the typehandler - declare typehandler globally in the config using the typehandler-tag When you choose the latter option, you can remove the typehandler on the resultmap too, iBATIS will resolve the typehandler automatically using the javatype. Some information about typehandlers: http://opensource2.atlassian.com/confluence/oss/display/IBATIS/How+do+I+use+a+Custom+Type+Handler+with+complex+property+or+Type+Safe+Enumeration Niels -----Original Message----- From: Reza Farsi [mailto:[EMAIL PROTECTED] Sent: vrijdag 21 oktober 2005 11:56 To: [email protected] Subject: iBaits ignores my TyeHandler Hi all, to handle the new Java 5 object type (enum), I started a test project to handle the enums. I simply define an object to be persisted called TestEnum. It has two attributes, an LangEnum (enum) and an integer. In my xml config file I defined the type handler for this attribute. After starting the test, getting objects works well. Saving fails due to NullPointerException. Debugging shows, that the type handler is null! I'm using iBaits 2.1.5 and JDK 5.0.01. Thanks in advance. Reza ------------------------------- Here the sqlMap and then the exception: <sqlMap> <typeAlias type="test.enums.TestEnum" alias="testEnum"/> <resultMap id="testEnum" class="testEnum"> <result property="id" column="id"/> <result property="currentLang" column="lang" javaType="test.enums.LangEnum" typeHandler="test.enums.TypeHandlerEnum"/> </resultMap> <select id="getAll" resultMap="testEnum"> select * from test_enum </select> <insert id="save" parameterClass="testEnum"> insert into test_enum (lang) values (#currentLang#) <selectKey keyProperty="id" resultClass="int"> select LAST_INSERT_ID() </selectKey > </insert> </sqlMap> and the exception: test.enums.TestEnum: id=1, lang=CH log4j:WARN No appenders could be found for logger (org.springframework.beans.factory.xml.XmlBeanDefinitionReader). log4j:WARN Please initialize the log4j system properly. Exception in thread "main" org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; --- The error occurred in TestEnum.xml. --- The error occurred while applying a parameter map. --- Check the save-InlineParameterMap. --- Check the parameter mapping for the 'currentLang' property. --- Cause: java.lang.NullPointerException; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in TestEnum.xml. --- The error occurred while applying a parameter map. --- Check the save-InlineParameterMap. --- Check the parameter mapping for the 'currentLang' property. --- Cause: java.lang.NullPointerException com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in TestEnum.xml. --- The error occurred while applying a parameter map. --- Check the save-InlineParameterMap. --- Check the parameter mapping for the 'currentLang' property. --- Cause: java.lang.NullPointerException Caused by: java.lang.NullPointerException at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate(GeneralStatement.java:94) at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:442) at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:81) at org.springframework.orm.ibatis.SqlMapClientTemplate$9.doInSqlMapClient(SqlMapClientTemplate.java:319) at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:181) at org.springframework.orm.ibatis.SqlMapClientTemplate.insert(SqlMapClientTemplate.java:317) at test.enums.IbatisEnumDao.save(IbatisEnumDao.java:36) at test.enums.Main.main(Main.java:37) Caused by: java.lang.NullPointerException at com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParameter(BasicParameterMap.java:165) at com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParameters(BasicParameterMap.java:125) at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:80) at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteUpdate(GeneralStatement.java:200) at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate(GeneralStatement.java:78) ... 7 more Caused by: java.lang.NullPointerException at com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParameter(BasicParameterMap.java:165) at com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParameters(BasicParameterMap.java:125) at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:80) at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteUpdate(GeneralStatement.java:200) at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate(GeneralStatement.java:78) at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:442) at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:81) at org.springframework.orm.ibatis.SqlMapClientTemplate$9.doInSqlMapClient(SqlMapClientTemplate.java:319) at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:181) at org.springframework.orm.ibatis.SqlMapClientTemplate.insert(SqlMapClientTemplate.java:317) at test.enums.IbatisEnumDao.save(IbatisEnumDao.java:36) at test.enums.Main.main(Main.java:37) -- 10 GB Mailbox, 100 FreeSMS/Monat http://www.gmx.net/de/go/topmail +++ GMX - die erste Adresse für Mail, Message, More +++
