File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Rogerio Kioshi
Ranch Hand
Posts: 690
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?



 
James Sutherland
Ranch Hand
Posts: 553
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Alex Armenteros
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic