wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Why does JPA change a datetime value from Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Why does JPA change a datetime value from "0000-00-00 00:00:00" to null?" Watch "Why does JPA change a datetime value from "0000-00-00 00:00:00" to null?" New topic
Author

Why does JPA change a datetime value from "0000-00-00 00:00:00" to null?

Rogerio Kioshi
Ranch Hand

Joined: Apr 12, 2005
Posts: 689
Hi,

I have a NOT NULL datetime column DATEAUTHORIZATION in a MySQL table. The records have the value "0000-00-00 00:00:00" in this field. I'm using JPA in my application, but when I read this datetime field, JPA changes it to null. If I want just update any other field (and not DATEAUTHORIZATION ) it raises an error complaining that the datetime field cannot be null.

Is there a way to make JPA transforms the value "0000-00-00 00:00:00" to a non nullable value?

How do I solve this problem?




SCEA 5 (part 1), SCBCD, SCWCD, SCJP, CLP, CLS
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
That is odd. Are you sure it is JPA and not your JDBC driver?

Try reading the value directly through JDBC, what is returned?

What JPA provider are you using?

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 69
That ยก's because the class used to represent datetimes in java is Timestamp and that class is incapable of represent that value


I've had the same problem in my hibernate program and solved it putting this in the url that connects to the DB

?zeroDateTimeBehavior=round

round puts the date to the nearest possible, have not checked which

round can be "null", to convert those dates to null.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Why does JPA change a datetime value from "0000-00-00 00:00:00" to null?
 
Similar Threads
Joda DateTime
unable to retrieve timestamp in my servlet
mysql date problem
unable to retrieve timestamp in my servlet
problem while insert date data in mysql