JPA / hibernate时间戳未被保存在数据库/对象实体中 [英] JPA/hibernate time stamp not getting saved in database/object entity

查看:133
本文介绍了JPA / hibernate时间戳未被保存在数据库/对象实体中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用javax.persistence作为我的实体对象。数据库的$ mysql
我的实体对象有一个字段entryDate

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

当我使用saveOrupdate方法保存对象时,只会保存日期。我也要
想保存时间戳以及日期。我没有明确设置日期,因为我有
已经声明它以及上面的字段声明。
我如何得到时间与日期一起保存。



谢谢。

解决方案

使用

  @Temporal(TemporalType.TIMESTAMP)

您的属性。


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 saveOrupdate 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.

这篇关于JPA / hibernate时间戳未被保存在数据库/对象实体中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆