I am getting the following error while persisting a LocalDate field [Using VARCHAR(20) type in column]:
Value too long for column "BIRTH_DATE VARCHAR(20)":"'aced00057372000d6a6176612e74696d652e536572955d84ba1b2248b20c00007870770703000007e2060c78' (88)";
The field definition is as follows:
@Column(name = "BIRTH_DATE")
private LocalDate date;
@Column(name = "BIRTH_TIME")
private LocalTime time;
I am using spring data starter (1.5.9.RELEASE). Which internally uses hibernate 5.0.12.
According to the blogpost https://www.thoughts-on-java.org/hibernate-5-date-and-time/
Hibernate 5, supports Java 8 features (DateTime API) out of the box. So, why this error is coming.
I have checked, and a valid LocalDate object is being created in run time. But the error is thrown while persisting. Here is the debug screenshot just before the call to save()

The error changes to the following, if I change column type to DATE:
java.lang.IllegalArgumentException: aced00057372000d6a6176612e74696d652e536572955d84ba1b2248b20c00007870770703000007e2060c78
at org.h2.util.DateTimeUtils.parseDateValue(DateTimeUtils.java:313) ~[h2-1.4.196.jar:1.4.196]
The string you’ve encountered is the hexadecimal representation of a serialized object, which can be verified easily:
ByteArrayInputStream is = new ByteArrayInputStream(new BigInteger(
"aced00057372000d6a6176612e74696d652e536572955d84ba1b2248b20c00007870770703000007e2060c78", 16)
.toByteArray());
is.read();
ObjectInputStream ois = new ObjectInputStream(is);
final Object obj = ois.readObject();
System.out.println(obj+" ("+obj.getClass().getName()+')');
2018-06-12 (java.time.LocalDate)
Of course, storing a LocalDate as such a blob is not a sign of a genuine DateTime API support, as that should be the last resort for storing a value. Either, there is no support or it has not been properly configured. In either case, you have to recheck the environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With