I am having some trouble figuring out how to return a single DateTime from a SQL query using mybatis:
The relevant part of my interface:
DateTime getMinActual(@Param("IDs") List<Integer> IDs);
The relevant part of my mapper xml:
<resultMap id="dtt" type="org.joda.time.DateTime">
<result column="dt" property="time" javaType="org.joda.time.DateTime" jdbcType="TIMESTAMP" typeHandler="org.joda.time.mybatis.handlers.DateTimeTypeHandler" />
</resultMap>
<select id="getMinActual" resultMap="dtt">
select min(cast(case when [quarter]=1 then '1/' when [quarter]=2 then '4/' when [quarter]=3 then '7/' else '10/' end + '1/' + cast([year] as varchar) as datetime)) as dt
from
Ops where id in
<foreach item="IDs" index="index" collection="IDs"
open="(" separator="," close=")">
#{IDs}
</foreach>
</select>
My issue seems to be with the property = "time" becaue I get this error:
org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'time' in 'class org.joda.time.DateTime'
I have tried all different property names such as DateTime, datetime, dateTime, org.joda.time.DateTime, etc...all with the same error.
Any ideas?
Update as pointed out JodaTime is immutable, but then this should work:
<resultMap id="dtt" type="org.joda.time.DateTime">
<constructor>
<idArg column="dt" javaType="org.joda.time.DateTime" typeHandler="org.joda.time.mybatis.handlers.DateTimeTypeHandler" />
</constructor>
</resultMap>