• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate & Joda DateTime - SQLException: expected DATE got BINARY

 
Simon Ritchie
Ranch Hand
Posts: 93
4
Eclipse IDE Hibernate 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
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • 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: 93
4
Eclipse IDE Hibernate 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 -

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic