Reputation: 24103
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
.
Which type should be the member in my java code?
Upvotes: 1
Views: 5003
Reputation: 11487
I have used LocalDateTime from joda package, and I have used "org.joda.time.contrib.hibernate.PersistentLocalDateTime" as the custom type in hibernate, and it works. Am not sure , if this is what you are using.
Upvotes: 0
Reputation: 80192
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.
Related post How to store date/time and timestamps in UTC time zone with JPA and Hibernate
If you only want to use joda-time then there are already converters written. You should use Joda time - Hibernate support library.
Upvotes: 1
Reputation: 1927
Hibernate manages natively java.util.Date
(and subclasses like java.sql.Date
).
In order to use Joda Time object in your object model you can use the Joda provided Hibernate types for Hibernate up to version 3.6, and the Usertype project for Hibernate 4.
Upvotes: 1
Reputation: 10050
You will have to write a converter from java.sql.time to jodatime period and use it in your mapping. This happens because in the database it will always store value as java.sql.Time
Upvotes: 0