Greetings all,
I wonder if any of you can assist me with a concern.
I have been experimenting with Spring Data Neo4j for Kotlin over the past few days.
Spring Boot version 2.2.4.RELEASE
Kotlin version 1.3.61
Neo4j version 4.0.0
As an example, if I set up a class such as:
@NodeEntity
data class Kennel constructor (@Id @GeneratedValue val id: Long? = null, @Relationship val dog: Dog) {
}
where a Dog is:
@NodeEntity
data class Dog constructor (@Id @GeneratedValue var id: Long? = null, @Relationship var name: String) {
}
and then try to save and load an object of this Kennel class:
@ExtendWith(SpringExtension::class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Transactional
class KennelRepositoryTest @Autowired constructor (val kennelRepository: KennelRepository,
val session: Session) {
var dogWrite: Dog = Dog(name = "rover");
var kennelWrite: Kennel = Kennel(dog = dogWrite)
@BeforeEach
fun beforeEach() {
session.purgeDatabase()
kennelRepository.save<Kennel>(kennelWrite)
session.clear()
}
@Test
fun findById() {
val kennelRead: Kennel = kennelRepository.findById(kennelWrite.id!!).orElseGet (null)
assertEquals(kennelWrite, kennelRead)
}
}
I see an IllegalArgumentException on findById of:
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method w.resourceserver.domain.Kennel.<init>, parameter dog
resulting from:
Caused by: org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate w.resourceserver.domain.Kennel using constructor fun <init>(kotlin.Long?, w.resourceserver.domain.Dog): w.resourceserver.domain.Kennel with arguments null,null,1,null
If I instead use an alternative Kennel with a Nullable dog
@NodeEntity
data class KennelWithNullable constructor (@Id @GeneratedValue val id: Long? = null, @Relationship val dog: Dog?) {
}
or a dog in a collection:
@NodeEntity
data class KennelWithSet constructor (@Id @GeneratedValue val id: Long? = null, @Relationship val dogSet: Set<Dog>) {
}
the findById method seems to work fine.
Is this expected behaviour or should I try and continue debugging ?
Many thanks for any feedback.