Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to map postgresql "timestamp with time zone" in a JPA 2 entity
    primarykey
    data
    text
    <p>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 ).</p> <p>I am having trouble mapping "timestamp with time zone" fields into my JPA entities. </p> <p>Here is an example:</p> <pre><code>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 ) ) </code></pre> <p>I have tried to map as follows:</p> <pre><code>@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 */ </code></pre> <p>I keep on getting an exception with the following root cause: <code>Caused by: org.hibernate.HibernateException: Wrong column type in public.backend_themetopic for column created. Found: timestamptz, expected: date</code></p> <p><strong>What I have tried</strong></p> <ul> <li>replacing <code>java.util.Calendar</code> with <code>java.util.Date</code> - made no difference</li> <li>using <code>java.sql.Timestamp</code> - complained that I cannot apply the <code>@Temporal</code> annotation to a <code>Timestamp</code></li> <li>using <code>org.joda.time.DateTime</code> with a custom <code>@Type</code> annotation ( <code>@Type(type="org.joda.time.contrib.hibernate.PersistentDateTimeTZ")</code> ) also did not work</li> </ul> <p><strong>Constraints</strong></p> <ul> <li>This application interacts with a "legacy system" - so, changing the types of the date fields is not a good option</li> </ul> <p>My question is: how should I map these timezone aware timestamps into my JPA entities?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload