ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From DelGurth <delgu...@gmail.com>
Subject Re: Mapping of a Set with enums
Date Mon, 18 May 2009 17:54:00 GMT
On Mon, May 18, 2009 at 7:40 PM, Mikael Andersson <mail.micke@gmail.com> wrote:
> Hi
>
> I'm having problems mapping to a property which is a Set of java5 enums.
>
> I have a class CounterpartyHedgeVO which has the property creditEvents which
> is a Set<CreditEventEnum>.
>
> Not sure what the problem is but I'm guessing that iBATIS tries to treat the
> Enum like a POJO and fails to create it since there isn't a public
> constructor. Or?
>
> Any help would be really appreciated.
>
> My current sqlmap (omitted the typeAlias definitions):
>
> <resultMap class="CounterpartyHedgeVO" id="CounterpartyHedgeVOResult"
> groupBy="refNo">
>     <result column="POS_RefNoADB" jdbcType="VARCHAR" property="refNo"/>
>    <result column="PRT_Code" jdbcType="VARCHAR" property="prtCode"/>
>       <result column="RBE_CodeCpty" jdbcType="VARCHAR"
> property="counterpartyCode"/>
>       <result column="POS_Tradebook"  jdbcType="VARCHAR"
> property="tradeBook"/>
>
>       <result resultMap="CDS_HEDGE.CreditEventEnumResult"
> property="creditEvents"/>
>  </resultMap>
>
>  <resultMap class="CreditEventEnum" id="CreditEventEnumResult">
>   <result column="CRE_EventType" property="value" jdbcType="VARCHAR"
> typeHandler="hedge.dao.CreditEventEnumReadOnlyTypeHandler"/>
>  </resultMap>
>
> Stack trace:
> --- The error occurred in ibatis/sqlmap-map-cds-hedge.xml.
> --- The error occurred while applying a result map.
> --- Check the CDS_HEDGE.CreditEventEnumResult.
> --- The error occured while instantiating the result object
> --- Cause: java.lang.RuntimeException: JavaBeansDataExchange could not
> instantiate result class.  Cause: java.lang.InstantiationException:
> hedge.interfaces.CreditEventEnum
>  at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:188)
>  at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(GeneralStatement.java:123)
>  at
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:615)
>  at
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:589)
>  at
> com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
>  at
> org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(SqlMapClientTemplate.java:298)
>  at
> org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:209)
>  ... 40 more
> Caused by: java.lang.RuntimeException: JavaBeansDataExchange could not
> instantiate result class.  Cause: java.lang.InstantiationException:
> hedge.interfaces.CreditEventEnum
>  at
> com.ibatis.sqlmap.engine.exchange.JavaBeanDataExchange.setData(JavaBeanDataExchange.java:108)
>  at
> com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectValues(BasicResultMap.java:373)
>  at
> com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setNestedResultMappingValue(BasicResultMap.java:449)
>  at
> com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.applyNestedResultMap(BasicResultMap.java:396)
>  at
> com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectValues(BasicResultMap.java:382)
>  at
> com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResultObject(RowHandlerCallback.java:64)
>  at
> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:382)
>  at
> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:301)
>  at
> com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQueryProcedure(SqlExecutor.java:283)
>  at
> com.ibatis.sqlmap.engine.mapping.statement.ProcedureStatement.sqlExecuteQuery(ProcedureStatement.java:34)
>  at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
>  ... 46 more
> Caused by: java.lang.InstantiationException:
> hedge.interfaces.CreditEventEnum
>  at java.lang.Class.newInstance0(Class.java:340)
>  at java.lang.Class.newInstance(Class.java:308)
>  at com.ibatis.common.resources.Resources.instantiate(Resources.java:294)
>  at
> com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactoryUtil.createObjectInternally(ResultObjectFactoryUtil.java:127)
>  at
> com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactoryUtil.createObjectThroughFactory(ResultObjectFactoryUtil.java:95)
>  at
> com.ibatis.sqlmap.engine.exchange.JavaBeanDataExchange.setData(JavaBeanDataExchange.java:106)
>  ... 56 more
>
> Cheers,
>  Micke

I think you will need to create a typehandler so iBATIS can work with your Enum.

See: http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+use+a+Custom+Type+Handler+with+complex+property+or+Type+Safe+Enumeration

Regards,
Wessel

Mime
View raw message