How to prevent hibernate from loading wrong dates?
<p>The problem is I get the wrong date from DAO's load function. </p>

<p>The observed date is stored in the PostgreSQL database (comes from the birthdate column from the User table) and is equal to 1982-03-28. It is sometimes fetched as 1982-03-27. I got some tip from more experienced users and they say that it is somehow connected to timezone issues.</p>

<p>The wrong values come from the java.util.Date class' instance. I get them by the Calendar class' object. When I call this little one:</p>

<pre><code>calendar.getTimeZone().getDisplayName()
</code></pre>

<p>it returns </p>

<pre><code>Central European Time
</code></pre>

<p>The BirthDate column's type is:</p>

<blockquote>
  <p>birthdate TIMESTAMP WITHOUT TIME ZONE</p>
</blockquote>

<p>The value of the timezone variable set in the postgresql.conf file equals to Poland.</p>

<p>The load method's inner implementation looks like this:</p>

<pre><code>public T load(ID aPrimaryKey, boolean aLock)
{
    if (aPrimaryKey == null) {
        throw new IllegalArgumentException("Parameter aPrimaryKey can't be null!");
    }
    preLoad(aPrimaryKey);
    T entity; if (aLock) {
        entity = _session.load(getEntityClass(), aPrimaryKey, LockMode.UPGRADE);
    } else
        entity = _session.load(getEntityClass(), aPrimaryKey);
    postLoad(entity);

    return entity;
}
</code></pre>

<p>My database version is </p>

<blockquote>
  <p>PostgreSQL 9.4.4 on x86_64-unknown-linux-gnu, compiled by gcc (Debian
  4.9.2-10) 4.9.2, 64-bit</p>
</blockquote>

<p>I use </p>

<blockquote>
  <p>hibernate-core-3.6.0.Final.jar</p>
</blockquote>

<p>My entity class looks like this (has few more fields):</p>

<pre><code>import javax.persistence.Column;

@javax.persistence.Entity
@javax.persistence.Table(name="User")
@javax.persistence.SequenceGenerator(name="userId", sequenceName="user_id_seq", allocationSize=1)
public class User {

   @javax.persistence.Id
   @Column(name="Id", nullable=false)
   @javax.persistence.GeneratedValue(strategy=javax.persistence.GenerationType.AUTO, generator="userId")
   private long id;

   @Column(name="Name")
   private String firstName;

   public User(String firstName, java.util.Date birthDate, java.util.Date registrationDate)
   {
       this.firstName = firstName;
       this.birthDate = birthDate;
       this.registrationDate = registrationDate;
   }

   @Column(name="BirthDate")
   @javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
   private java.util.Date birthDate;

   @Column(name="RegistrationDate", nullable=false)
   @javax.persistence.Temporal(javax.persistence.TemporalType.TIMESTAMP)
   private java.util.Date registrationDate;

   public String toString()
   {
       return firstName + " should clean himself...";
   }

   public User() {}
}
</code></pre>

<p>I changed the type of <code>birthdate</code> field to <code>TIMESTAMPTZ</code> - then everything appears to work well. But how to solve to problem without changing the column's data type? Do you have any tips?</p>