在Oracle Ibatis中将TIMESTAMP转换为Char

时间:2014-05-23 08:29:22

标签: java sql oracle ibatis

我正在尝试在Oracle ibatis中运行查询以获取表的内容。列'CREATED_ON'之一是TIMESTAMP数据类型。当我尝试使用TO_CHAR函数将其转换为String时,我得到以下异常。

目标是获取列标题的地图和&此查询中的值。如果我从查询中删除TO_CHAR,我会在Map中得到结果而没有任何异常,但CREATED_ON列值是oracle.sql.TIMESTAMP@3524fead。

EXCEPTION

com.ctg.dms.exceptions.DMSApplicationException: com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in com/ctg/dms/dao/ibatis/oracle/AuditLogAccessControlSQLs.xml.  
--- The error occurred while applying a result map.  
--- Check the auditLogAccessControl.findAccessLogEntriesForFileExport-AutoResultMap.  
--- Check the result mapping for the 'TO_CHAR(A.CREATED_ON)' property.  
--- Cause: com.ibatis.common.beans.ProbeException: There is no WRITEABLE property named 'CREATED_ON)' in class 'java.lang.Object'at com.ctg.dms.dao.impl.sql.ibatis.AuditLogAccessControlDAOImpl.findAccessLogEntriesForFileExport(AuditLogAccessControlDAOImpl.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy11.findAccessLogEntriesForFileExport(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)

Ibatis XML Mapping

<statement id="findAccessLogEntriesForFileExport" resultClass="HashMap">
   SELECT (SELECT VALUE FROM REF_DATA WHERE ID_REF_DATA = A.ID_EVENT_TYPE) EVENT_TYPE, 
      A.DESCRIPTION AS DESCRIPTION, U.USERNAME AS CREATED_BY, TO_CHAR(A.CREATED_ON, 'DD-MM-YYYY')
   FROM AUDIT_LOG_ACCESS_CONTROL A
   JOIN USER_DETAILS U  ON A.CREATED_BY = U.ID_USER_DETAILS
   ORDER BY A.CREATED_ON DESC
</statement>

1 个答案:

答案 0 :(得分:0)

我不知道Abatis,但似乎需要将此字段映射到java对象中的字段。你应该给这个函数一个别名(=&gt; TO_CHAR(A.CREATED_ON,'DD-MM-YYYY')CREATED_ON),并确保你的java定义中的类型(VARCHAR2 / STRING)匹配。