<p>I'm experiencing the following very annoying behaviour when using JPA entitys in conjunction with Oracle 10g. </p>

<p>Suppose you have the following entity.</p>

<pre><code>@Entity
@Table(name = "T_Order")
public class TOrder implements Serializable {
    private static final long serialVersionUID = 2235742302377173533L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @Column(name = "activationDate")
    private Calendar activationDate;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Calendar getActivationDate() {
        return activationDate;
    }

    public void setActivationDate(Calendar activationDate) {
        this.activationDate = activationDate;
    }
}
</code></pre>

<p>This entity is mapped to Oracle 10g, so in the DB there will be a table <code>T_ORDER</code> with a primary key <code>NUMBER</code> column <code>ID</code> and a <code>TIMESTAMP</code> column <code>activationDate</code>.</p>

<p>Lets suppose I create an instance of this class with the activation date <code>15. Sep 2008 00:00AM</code>. My local timezone is CEST which is <code>GMT+02:00</code>. When I persist this object and select the data from the table <code>T_ORDER</code> using sqlplus, I find out that in the table actually <code>14. Sep 2008 22:00</code> is stored, which is ok so far, because the oracle db timezone is GMT.</p>

<p>But now the annoying part. When I read this entity back into my JAVA program, I find out that the oracle time zone is ignored and I get <code>14. Sep 2008 22:00 CEST</code>, which is definitly wrong. </p>

<p>So basically, when writing to the DB the timezone information will be used, when reading it will be ignored.</p>

<p>Is there any solution for this out there? The most simple solution I guess would be to set the oracle dbs timezone to <code>GMT+02</code>, but unfortunatly I can't do this because there are other applications using the same server.</p>

<p>We use the following technology</p>

<p>MyEclipse 6.5
JPA with Hibernate 3.2
Oracle 10g thin JDBC Driver</p>

[{'answer_id': 82416, 'author': 'Jeroen Wyseur', 'author_id': 15490, 'author_profile': 'https://Stackoverflow.com/users/15490', 'pm_score': 0, 'selected': False, 'text': '<p>I already had my share of problems with JPA and timestamps. I\'ve been reading in the <a href="http://forums.oracle.com/forums/thread.jspa?threadID=612075" rel="nofollow noreferrer">oracle forums</a> and please check the following:</p>\n\n<ul>\n<li>The field in the database should be TIMESTAMP_TZ and not just TIMESTAMP</li>\n<li>Try adding the annotation @Temporal(value = TemporalType.TIMESTAMP)</li>\n<li>If you don\'t really need the timezone, put in a date or timestamp field.</li>\n</ul>\n'}, {'answer_id': 85329, 'author': 'davetron5000', 'author_id': 3029, 'author_profile': 'https://Stackoverflow.com/users/3029', 'pm_score': 3, 'selected': True, 'text': '<p>You should not use a Calendar for accessing dates from the database, for this exact reason.  You should use <code>java.util.Date</code> as so:</p>\n\n<pre><code>@Temporal(TemporalType.TIMESTAMP)\n@Column(name="activationDate")\npublic Date getActivationDate() {\n    return this.activationDate;\n}\n</code></pre>\n\n<p><code>java.util.Date</code> points to a moment in time, irrespective of any timezones.  Calendar can be used to format a date for a particular timezone or locale.</p>\n'}]
['https://Stackoverflow.com/questions/82235', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/15657/']