开发者

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

开发者 https://www.devze.com 2023-04-13 08:45 出处:网络
using TimeDuration in one of my Grails/Groovy classes 开发者_JAVA百科I get an exception when starting the grails app.

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

精彩评论

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