3
votes

using TimeDuration in one of my Grails/Groovy classes 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?

3
Indirect answer: install the joda plugin and use Joda Durations. The plugin maps the user types automatically for you. - Rob Hruska
I thought about this before, but wanted to try without it at first. thanks for remarking again! - skurt
No problem. From what I've seen, it looks like you'd probably have to write your own UserType to correctly persist the field. - Rob Hruska
persisting is done by the plugin, that works fine. But what I did not found yet is how to handle joda-time to and from string!? - skurt
If you add your comment as an answer, I would mark this as the solution. - skurt

3 Answers

3
votes

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.

0
votes

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.

0
votes
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..