Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded null-object are not allowed [DATAJDBC-364] #588

Closed
spring-projects-issues opened this issue Apr 16, 2019 · 1 comment
Closed

Embedded null-object are not allowed [DATAJDBC-364] #588

spring-projects-issues opened this issue Apr 16, 2019 · 1 comment
Assignees

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Apr 16, 2019

Alexandra Faynveyts opened DATAJDBC-364 and commented

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.

data class Outer(    
@Id     
val id: Long,

val value: String,

@Embedded     
inner: Inner? = null
)

 

data class Inner(    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


Issue Links:

  • DATAJDBC-374 Make behavior for empty embeddables configurable

Referenced from: commits 23bee70, 3a89ec0

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 17, 2019

Jens Schauder commented

This was resolved as part of DATAJDBC-370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants