Oracle Timezone retrieval through Hibernate

Hibernate doesn’t provide any direct way to retrieve the oracle column with datatype "TIMESTAMP WITH TIMEZONE" and generally the timezone information is lost because the date is retrieved by hibernate after converting it according to local timezone. I couldn’t find any solution for quite sometime until I came to know that there are couple of ways around the problem for solving it. One solution is to use type ( which becomes difficult to implement when you are having a database containing more than hundreds of tables having columns of type "TIMESTAMP WITH TIMEZONE".

Other solution is simple and helps in avoiding usage of type in hibernate. Suppose we are having a column with name DATE_TIME and type "TIMESTAMP WITH TIMEZONE" in database. Follow these steps for POJO –

1. Declate data type of dateTime as Calendar.

2. Use following annotations for get method –


            @Column(name = "DATETIME", length = 7,columnDefinition="TIMESTAMP WITH TIMEZONE")

It is quite simple step if you are familiar with hibernate templates otherwise I would suggest you to start using them for POJO generation!

Leave a Reply

Your email address will not be published. Required fields are marked *