• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Hibernate & Joda DateTime - SQLException: expected DATE got BINARY

 
Ranch Hand
Posts: 179
13
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I'm trying to incorporate Joda DateTime into my project but am having an issue.  There is a database table (Oracle database) that contains a date column that is of Oracle's Date format.  I'm using Hibernate to map the data in this table into an object.  The object has a variable of type java.util.Date which maps to the date column.  Everything has been working fine.  

But now I've changed the variable to a DateTime type and updated the Hibernate mapping file to change the property type to org.joda.time.DateTime.  I've changed my data access code that queries this table to reflect the change



I'm getting an error at this line:

this.myObjects = this.criteria.list();





It looks to me like Hibernate doesn't recognise the Joda class.  How can I amend this?

Thanks
 
Rancher
Posts: 4399
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only java.util.Date (and its subclasses) are mapped to DATE columns.
Since the JDBC driver does not have a mapping for the Joda time class you are using it falls back to assuming its a BINARY.

Essentially, you can't use those classes with your column mappings without some extra bells and whistles.
This might be a useful thing to look at:
http://joda-time.sourceforge.net/contrib/hibernate/userguide.html

I think it adds a mapping layer over the top of Hibernate to translate to/from the old Date/Timestamp classes to Joda ones.
 
Simon Ritchie
Ranch Hand
Posts: 179
13
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Dave.

I removed the references to the Joda classes in my Hibernate mapping file and returned them to the java.util.Date references.  In my class that queries the data, I used the following code that allows users to pass in a DateTime variable which is then converted to java.util.Date then to java.sql.Date, for anyone who's interested -

 
Everybody's invited. Even this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!