hibernate - Storing date, time, and timezone in PostgreSQL with Grails and GORM -
i have grails 2.5.3 application connecting postgresql, , want store java date
or calendar
object in database, , include time zone.
based on postgresql documentation, default timestamp type not include time zone, need use timestamptz
type include time zone.
unfortunately when try set in mapping
closure of domain class, fails. i'm trying use this:
createddate type: 'timestamptz'
and error receive is:
nested exception org.hibernate.mappingexception: not determine type for: timestamptz
unfortunately list of hibernate types not seem include map value. ones related dates are: date
, time
, timestamp
, calendar
, calendar-date
. have tested each of these, , none of them create desired timestamp time zone
in postgres.
there articles talk creating custom hibernate usertype
this, seems common use case, , can't think there should let me working out of box.
you can create own dialect , map java type sql type. can see how it's done in grails-postgresql-extensions plugin , subclass dialect or default postgresql one.
package my.company import java.sql.types import groovy.transform.compilestatic import net.kaleidos.hibernate.postgresqlextensionsdialect @compilestatic class sqdialect extends postgresqlextensionsdialect { sqdialect() { registercolumntype(types.timestamp, 'timestamp time zone') } }
Comments
Post a Comment