JPA实体:从Oracle DATE列获取小时,分钟和秒 [英] JPA entity: get the hours,minutes and sec from Oracle DATE column
问题描述
我在从Oracle数据库(dd/mm/yyyy hh/mm/ss)获取完整的DATE信息时遇到问题.
I have problems to get the full DATE info from my Oracle DB (dd/mm/yyyy hh/mm/ss).
在数据库级别中,我要接收的列中设置测试值:
In the db level, in the column that I want to receive I set test values:
update my_table
set my_date_column=(to_date('2011-06-15 15:43:12', 'yyyy-mm-dd hh24:mi:ss'));
但是在我的JPA实体中,我有:
but in my JPA entity I have:
@Column(name = "MY_DATE_COLUMN")
@Temporal(TemporalType.DATE)
private Date dateDetailed;
public Date getDateDetailed() {
if (this.dateDetailed!= null) {
return this.dateDetailed;
}
return null;
}
public void setDateDetailed(Date dateDetailed) {
if (dateDetailed!= null) {
this.dateDetailed= dateDetailed;
} else {
this.dateDetailed= null;
}
}
每次访问我的对象时,它都会给我提供没有小时,分钟和秒的日期.
Each time I acccess my object, It is giving me date without hours, min and seconds.
我尝试使用TemporalType.TIMESTAMP,但是在那种情况下,我还需要更改db中的列类型(我想避免这种情况).
I tried to use TemporalType.TIMESTAMP, but in that case I would need to also change column type in db (which I want to avoid).
有什么建议吗?
推荐答案
它是TemporalType.DATE
您将需要TIME或TIMESTAMP. DATE只是没有时间的日期. TIMESTAMP以数字表示.
Its the TemporalType.DATE
You will need TIME or TIMESTAMP. DATE is only the date without time. TIMESTAMP is represented as a number.
这篇关于JPA实体:从Oracle DATE列获取小时,分钟和秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!