<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: How to work with NULL-Values in DateTime-Types using persistence?</title><link>https://answers.axonivy.com/questions/1369/how-to-work-with-null-values-in-datetime-types-using-persistence</link><description>&lt;p&gt;We are facing the following problem: We are using the persistence-feature to handle complex objects. During the fetch we get values where a datetime-field is not set (NULL in the database) - when we try to write the entity object instance back to the database (merge) we get the following exception:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;"SQLException: Only dates between January 1, 1753 and December 31, 9999 are accepted.
    DataException: could not update: [de.*****.qia.persistence.QuestionnaireQuestion#130]
    PersistenceException: org.hibernate.exception.DataException: could not update: [de.*****.qia.persistence.QuestionnaireQuestion#130]
    RollbackException: Error while committing the transaction
    Failed to excecute operation "merge" for persistence unit "qiaPersistence".
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The reason is quite obvious - the auto-initialized value is out of the allowed range for the MSSQL-Server. But shouldn't NULL be the value to be written back?&lt;/p&gt;
&lt;p&gt;How can we adress this? A workaround would be to enforce that a date is created during the initial persist but there could be situation where "NULL" is programmtically a valid entry.&lt;/p&gt;
&lt;p&gt;How can we adress this issue?&lt;/p&gt;
&lt;p&gt;Edit:
RDBMS: MSSQL Express 2008&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/1369/how-to-work-with-null-values-in-datetime-types-using-persistence" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 05 Dec 2016 20:16:11 -0500</lastBuildDate><item><title>Answer by RemiMorin</title><link>https://answers.axonivy.com/questions/1369/how-to-work-with-null-values-in-datetime-types-using-persistence/2242</link><description>&lt;p&gt;Faces similar problems here, we were able  to save auto-initialized date but they were still a pain. Empty date became 0001-01-01.  &lt;/p&gt;
&lt;p&gt;I've fixed it when saving, nice, but now and then when we display a new object we still get 0001-01-01 date in p:calendar into the UI. We will probably find them elsewhere too I guess (data export, reports and the like).  &lt;/p&gt;
&lt;p&gt;We have to track every single one of them and fix them to make sure to display empty date. This is very annoying and not always obvious. It would be great that initialized/uninitialized state don't temper with the data itself.  &lt;/p&gt;
&lt;p&gt;If any global fix exist for that I would be interested.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">RemiMorin</dc:creator><pubDate>Mon, 05 Dec 2016 20:16:11 -0500</pubDate><guid>https://answers.axonivy.com/questions/1369/how-to-work-with-null-values-in-datetime-types-using-persistence/2242</guid></item><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/1369/how-to-work-with-null-values-in-datetime-types-using-persistence/1372</link><description>&lt;p&gt;There exists an utility which can set auto initialized data class values back to NULL. So you could use it to restore a valid state before you merge it to persistency.
Its published here: &lt;a href="http://sourceforge.net/projects/ivysupplements/files/Helper/"&gt;http://sourceforge.net/ivySupplement/dataClassNuller&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I did not test if this implementation still works with an up to date ivy version.
So you have to verify and test it.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Mon, 22 Jun 2015 09:02:56 -0400</pubDate><guid>https://answers.axonivy.com/questions/1369/how-to-work-with-null-values-in-datetime-types-using-persistence/1372</guid></item></channel></rss>