Arvind Sridharan
Arvind Sridharan

Reputation: 4045

How do i map a sql Time type to a java type using hibernate?

I've got a sql data type of TIME. Now, the data for 12:00 AM is stored as 00:00:00.

In the POJO that is mapped to the table, I have given the datatype as java.util.Date as per the hibernate specification. However, on loading a row that has the data type 00:00:00 i get this exception.

Cannot convert value '00:00:00' from column 18 to TIMESTAMP

How do I solve this?

Upvotes: 0

Views: 2395

Answers (1)

Carsten
Carsten

Reputation: 1511

For SQLServer you can use something like this. It should also work for time types I guess.(I don't know if it changes for other DB types)

private Date lockedUntil;
@Column(name="DATE", columnDefinition="DATETIME")
@Temporal(TemporalType.TIMESTAMP)
public Date getDate() {
    return date;
}

Upvotes: 1

Related Questions