0

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>
mrkb80
  • 581
  • 2
  • 8
  • 25

1 Answers1

0

As far as I know you need to use a type handler as you are doing but with the property set as per below example.

e.g.

<idArg column="dt" property="dt" javaType="org.joda.time.DateTime" typeHandler="org.joda.time.mybatis.handlers.DateTimeTypeHandler"/>

I used this github project as guide on how to use TypeResolver

fillup
  • 118
  • 4
  • yeah...tried that, but no dice. I also used that github project as my guide. I ended up just creating a wrapper class and using a resultMap. Works, just not as pretty as I want. – mrkb80 Aug 30 '15 at 13:41
  • You should post your solution here so that anyone else having this issue can resolve it also – fillup Aug 30 '15 at 21:36