开发者

JPA/hibernate time stamp not getting saved in database/object entity

开发者 https://www.devze.com 2023-02-07 07:04 出处:网络
I am using javax.persistence for my entity object.Mysql for database My entity object has a field entryDate

I am using javax.persistence for my entity object.Mysql for database My entity object has a field entryDate

@Column(name = "ENTRYDATE")   
private Date entryDate=new Date();

and when i save the object using sav开发者_如何学JAVAeOrupdate method only the date gets saved. I also want to save the time stamp along with date. I do not explicitly set the date since i have already declared it along with the field declaration above. How can i get time also to be saved along with date.

Thank you.


Use

@Temporal(TemporalType.TIMESTAMP) 

on your attribute.


@Column(name = "ENTRYDATE")  
@Temporal(TemporalType.TIMESTAMP) 
private Date entryDate=new Date();

Try to use this if you want to save timestamp otherwise you can use TemporalType.Date (for saving only date) and TemporalType.Time (for saving only time)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号