Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Hibernate & Joda DateTime - SQLException: expected DATE got BINARY

 
Ranch Hand
Posts: 189
14
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
 
Master Rancher
Posts: 4668
49
  • 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: 189
14
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 -

 
They worship nothing. They say it's because nothing is worth fighting for. Like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic