I'm new to Hibernate and am working with an Oracle 10g database. We have columns in our tables that are of type TIMESTAMP WITH TIMEZONE
. Hibernate does not seem to support this mapping directly. Is there a standard way to go about this?

- 5,179
- 10
- 35
- 56
2 Answers
An example of a UserType storing java.util.Calendar with time zone information is given in this blog post: http://www.joobik.com/2010/12/mapping-dates-and-time-zones-with.html
-
9don't post just a link otherwise your answer is worthless if the link breaks – sra Jan 02 '12 at 09:01
-
Updated link: http://www.joobik.com/2010/12/mapping-dates-and-time-zones-with.html – Jeff Walker Jun 15 '17 at 14:01
TIMESTAMP WITH TIMEZONE
is Oracle extension and thus is not supported by Hibernate out of the box. You have two options:
1) Change your table structure to store timezone in a separate column (as VARCHAR2). Hibernate is able to map java.util.TimeZone as timezone
type using its ID.
2) Write a custom class to hold both timestamp and timezone and a custom UserType that would persist it. It will have to be a CompositeUserType if you need the ability to use its individual properties (e.g. timezone or timestamp) in queries. Look at this example to get you started; you'll need to alter it to actually store the timezone.

- 99,456
- 24
- 206
- 195
-
5According to SQL in a Nutshell by Kline et al, TIMESTAMP WITH TIMEZONE is a type defined by SQL 2003. Thus, it's not an Oracle extension. – John Oct 18 '09 at 16:59
-
1Call it "SQL 2003 extension implemented by Oracle" then. It's still not supported by Hibernate – ChssPly76 Oct 18 '09 at 17:41
-
java.util.Calendar holds both timestamp and time zone information. Therefore solution by joobik seems better to me. – sax Jan 03 '12 at 18:49