I am trying to persist an object containing an embedded one using Spring Data JDBC. And it is not saved because it does not pass a null-check.I am trying to persist an object containing an embedded one using Spring Data JDBC. And it is not saved because it does not pass a null-check.
I created an outer class to persist.
val id: Long,
val value: String,
inner: Inner? = null
data classInner( val innerValue1: String, val innerValue2: String)
In the DB I would like to have only one table for Outer which contains fields id, value, inner_value_1 and inner_value_2. That's why I put @Embedded annotation on the inner-field.
id and value should be obligatory fields. innver_value_1 and invver_value_2 might be null,
The problem appears when I try to save null-inner object (which is nullable both in Kotlin and in the DB).
val outer = Outer(15, "value")
repo.save(outer) //throws an exception
The saving to repo operation throws an exception cause expects inner not to be null:
Caused by:java.lang.IllegalArgumentException:Target bean must not be null! at org.springframework.util.Assert.notNull(Assert.java:198) at org.springframework.data.mapping.model.BasicPersistentEntity.verifyBeanType(BasicPersistentEntity.java:550) at org.springframework.data.mapping.model.BasicPersistentEntity.getPropertyAccessor(BasicPersistentEntity.java:453)
The difficulty is that in Kotlin I cannot pass an object with null-valued-fields (because they are not nullable).
I think the null-objects should be mapped into the null-values
DATAJDBC-374 Make behavior for empty embeddables configurable