开发者

Correct Hibernate type for TimeDuration in grails/groovy domain class?

using TimeDuration in one of my Grails/Groovy classes 开发者_JAVA百科I get an exception when starting the grails app.

org.hibernate.MappingException: Could not determine type for: groovy.time.TimeDuration

usage in domain class

import groovy.time.TimeDuration
class Result {
    TimeDuration overall
}

which type should I define?


Since you're using Grails it would probably be more convenient to use the Joda Time plugin and its Duration type to store your values.

The plugin, when installed, provides Hibernate mappings for many of the library's types (including Duration).

It's likely that if you continue along with Groovy's TimeDuration that you'll have to write your own UserType; I didn't find one after a few searches.


Try using Date. This will use the default "timestamp" for the date type in the db. Optionally you can configure hibernate specifically with other formats for your Date field via hbm files/annotations.


import groovy.time.TimeDuration

class Result {
    Date overall
}

You can use this Date type for storing date and time, and this date and time will be mapped to timestamp by hibernate..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜