Derek Mahar
Derek Mahar

Reputation: 28386

How can I instruct Hibernate to map a Java date to an Oracle DATE column using a time zone other than the local time zone?

How can I instruct Hibernate to map a Java date to and from an Oracle DATE column using a time zone other than the local time zone?

Upvotes: 1

Views: 1412

Answers (2)

joobik
joobik

Reputation: 57

Hibernate does not allow for specifying time zones by annotation or any other means. If you use Calendar instead of date, you can implement a workaround using HIbernate property AccessType and implementing the mapping yourself. The more advanced solution is to implement a custom UserType to map your Date or Calendar. Both solutions are explained in this blog post: http://dev-metal.blogspot.com/2010/11/mapping-dates-and-time-zones-with.html

Upvotes: 0

Pascal Thivent
Pascal Thivent

Reputation: 570615

I'm not sure but I think that you'll have to use the OracleConnection.setSessionTimeZone(String regionName) method to set the session time zone.

To do that on the OracleConnection before having Hibernate dealing with it, the cleanest way would be to provide and use a custom implementation of o.h.c.ConnectionProvider.

See this related question.

Upvotes: 1

Related Questions