Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: @UpdateTimestamp generates value on persist too
PostPosted: Sun May 28, 2017 10:07 pm 
Newbie

Joined: Sun May 28, 2017 10:01 pm
Posts: 1
Hi all,

I am facing the issue that both @CreationTimestamp and @UpdateTimestamp record datetime simultaneously in database. For instance, once I saved my data entry, the datatime was recorded at both enteredDate property and modifiedDate property. What should I do to solve the issue? Any guidance will be appreciated.

My code:
Code:
    @CreationTimeStamp
    @Column(name="ENTERED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date enteredDate;

    @UpdateTimeStamp
    @Column(name="MODIFIED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date modifiedDate;

    //getters and setters

Thanks.

Brian


Top
 Profile  
 
 Post subject: Re: @CreationTimestamp and @UpdateTimestamp issue
PostPosted: Mon May 29, 2017 1:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1590
Location: Romania
The @UpdateTimestamp saves the creation timestamp as well. That's how it works. You can take a look at the GenerationTiming values to understand better the timing options. So, the INSERT phase is used by @CreationTimestamap while ALWAYS is used by @UpdateTimestamp, hence the observed behavior.

Further, when you modify the entity, the modifiedDate will be updated while enteredDate will not.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.