开发者

which datatype for using a time in gorm?

how can i handle a time (like 14:33) during calculations and savings in database? What datatype can i use for this in a HSQL DB?

I开发者_如何学C want to calculate things like workload or rest time. Is there a built in possibility to convert times to decimals?

Thanks!


As for the time representation, the most convenient type ought to be Joda Time's LocalTime.
There are several converters available to map the LocalTime type to the database.

You need the JAR packages joda-time and joda-time-hibernate.

Your domain class then might look like this:

import org.joda.time.contrib.hibernate.PersistentLocalTimeAsTime
import org.joda.time.LocalTime

class TimeDomain {
    LocalTime localTime

    static mapping = {
        localTime type: PersistentLocalTimeAsTime
    }

    // business logic would belong to a service class
    LocalTime plusMinutes(int minutes) {
        localTime.plusMinutes(minutes)
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜