开发者

JPA entity: get the hours,minutes and sec from Oracle DATE column

开发者 https://www.devze.com 2023-03-12 17:19 出处:网络
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:

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'));

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.

I tried to use TemporalType.TIMESTAMP, but in that case I would need to also change co开发者_开发技巧lumn type in db (which I want to avoid).

Any suggestions?


Its the TemporalType.DATE You will need TIME or TIMESTAMP. DATE is only the date without time. TIMESTAMP is represented as a number.


By using the TIMESTAMP temporal type, you will get the date and the time part of the java date datatype but Oracle will make a column with the TIMESTAMP datatype. To overcome this issue if you want a DATE datatype, you can use the columnDefinition parameter of the column annotation such as:

@Column(name = "MY_DATE_COLUMN", columnDefinition = "DATE")
@Temporal(TemporalType.TIMESTAMP)
private Date dateDetailed;
0

精彩评论

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