Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get hibernate to store a date?
    primarykey
    data
    text
    <p>I have a Spring / Hibernate project and I am trying to store a date into the database but it's not working. It must be something stupid but I have no idea what I am doing wrong.</p> <p>Here is my code: </p> <pre><code>user.setFailedPasswordAnswerAttemptCount(0); user.setLastLoginDate(new Date()); user.setIsOnline(true); </code></pre> <p>The other two variables (failedPasswordAnswerAttemptCount and isOnline) are getting written to the database without issue. I have also tried it with just passing a java.util.Date instead of a java.sql.Timestamp...same result. Here is how the property is defined on the user object: </p> <pre><code>private Date lastLoginDate; @Temporal(TemporalType.TIMESTAMP) @Column(name="last_login_date") public Date getLastLoginDate() { return this.lastLoginDate; } public void setLastLoginDate(Date lastLoginDate) { this.lastLoginDate = lastLoginDate; } </code></pre> <p>Here is the column definition: </p> <pre><code>`last_login_date` datetime DEFAULT NULL </code></pre> <p>Any help? I don't even know what else to look for as this should be working. </p> <p>Some more detail about the error: No errors or strange messages in the hibernate log. The hibernate log is showing a parameterized query but it isn't telling me what it is actually writing. It looks like it's not updating the column at all. In other words, if there is already a date there it doesn't change, or if it is null it doesn't change.</p> <p>Update: I have looked at the logs and it looks like hibernate does write the proper data, but then immediately writes the incorrect data again. I see the following entry in the log: </p> <pre><code>11:15:12.280 [http-bio-8080-exec-26] TRACE o.h.e.def.AbstractSaveEventListener - detached instance of: com.hi.model.User 11:15:12.280 [http-bio-8080-exec-26] TRACE o.h.e.def.DefaultMergeEventListener - merging detached instance </code></pre> <p>And right after that I see it putting the old value back in for the lastLoginDate.</p>
    singulars
    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