Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map MySql datetime to hibernate

I have a datetime field in my MySql database. A typical entry looks like this: 2015-08-26 11:45:48.

But by the time it reaches my app the hours, minutes and seconds are always 00:00:00.

This is the mapping entry:

<property name="listingTime" column="listing_time"/>         

The field in my Java class is

private java.sql.Timestamp startTime;

I tried setting various types for the listingTime property in my hibernate.cfg.xml but it doesn't change the all zeroes. What am I missing?

like image 720
Eddy Avatar asked Sep 06 '25 03:09

Eddy


1 Answers

Better use annotations like this:

...
@Column
@Type(type="timestamp")
private Date listing_time;

OR you can do it this way, and if you don't want it to change see the "updateable"

@Column(name = "created", nullable = false, updatable=false)
@Temporal(TemporalType.TIMESTAMP)
private Date created;
like image 109
franklinexpress Avatar answered Sep 07 '25 21:09

franklinexpress