简体   繁体   中英

Mysql: java.sql.Time datatype using java and hibernate returns back java.sql.Date

This seems to be very simple but somehow it is not working. I have to keep just the open time of a particular store in DB. I am using Time datatype of mysql for this. While storing i am doing:

java.sql.Time open = java.sql.Time.valueOf("09:00:00");

This works fine while storing the value in DB, but while fetching it, it return the value as 1970.01.01 09:00:00 I am using java and hibernate for the same.

I found this article java.sql.Time object being confused with java.sql.Date object

Is there just a simple way to achieve this..

Thanks Vish

@Temporal(TemporalType.TIME)
java.util.Date getDepartureTime() { ... } // persistent property           

According to the JBoss documentation on annotations , this will solve your problem. java.sql.* is JDBC-specific. JPA/JDO/etc. use java.util.Date instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM