在java和hibernate中的时间 [英] time in java and hibernate

查看:87
本文介绍了在java和hibernate中的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是hibernate的新手。我在我的DB(mySQL)中有一个startTime列的表。它的类型是时间。

我下载了org.joda.time包并使用了Period类型,但这不起作用并抛出异常:10954 [main] ERROR org.hibernate。 property.BasicPropertyAccessor - 预期类型:org.joda.time.Period,实际值:java.sql.Time

I am new with hibernate. I have an table in my DB (mySQL) with "startTime" column. It's type is time.
I downloaded org.joda.time package and use Period type, but this doesn't work and throws exception: 10954 [main] ERROR org.hibernate.property.BasicPropertyAccessor - expected type: org.joda.time.Period, actual value: java.sql.Time.

应该是哪种类型在我的java代码中的成员?

Which type should be the member in my java code?

推荐答案

您应该始终以UTC在数据库中存储日期和时间。 java.util.Date 是您应该使用的,因为它表示UTC中的日期和时间,并且hibernate支持它。

you should always store date and time in UTC in database. java.util.Date is what you should use as it represents the date and time in UTC and hibernate supports it.

href =https://stackoverflow.com/questions/508019/jpa-hibernate-store-date-in-utc-time-zone>如何使用JPA和Hibernate在UTC时区存储日期/时间和时间戳

Related post How to store date/time and timestamps in UTC time zone with JPA and Hibernate

如果您只想使用joda-time,那么已经有转换器写入。您应该使用乔达时间 - Hibernate支持库。

If you only want to use joda-time then there are already converters written. You should use Joda time - Hibernate support library.

这篇关于在java和hibernate中的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆