I have a JPA 2 application ( with Hibernate 3.6 as the JPA implementation ) that uses Postgresql ( with the 9.0-801.jdbc3 JDBC driver ).
I am having trouble mapping "timestamp with time zone" fields into my JPA entities.
Here is an example:
CREATE TABLE theme
(
id serial NOT NULL,
# Fields that are not material to the question have been edited out
run_from timestamp with time zone NOT NULL,
run_to timestamp with time zone NOT NULL,
CONSTRAINT theme_pkey PRIMARY KEY (id ),
CONSTRAINT theme_name_key UNIQUE (name )
)
I have tried to map as follows:
@Entity
@Table(schema = "content", name = "theme")
public class Theme extends AbstractBaseEntity {
private static final long serialVersionUID = 1L;
@Column(name = "run_from")
@NotNull
@Temporal(TemporalType.TIMESTAMP)
private Date runFrom;
@Column(name = "run_to")
@NotNull
@Temporal(TemporalType.TIMESTAMP)
private Date runTo;
/* The rest of the entity has been edited out */
I keep on getting an exception with the following root cause: Caused by: org.hibernate.HibernateException: Wrong column type in public.backend_themetopic for column created. Found: timestamptz, expected: date
What I have tried
- replacing
java.util.Calendarwithjava.util.Date- made no difference - using
java.sql.Timestamp- complained that I cannot apply the@Temporalannotation to aTimestamp - using
org.joda.time.DateTimewith a custom@Typeannotation (@Type(type="org.joda.time.contrib.hibernate.PersistentDateTimeTZ")) also did not work
Constraints
- This application interacts with a "legacy system" - so, changing the types of the date fields is not a good option
My question is: how should I map these timezone aware timestamps into my JPA entities?