Kotlin 1.4.31
Spring Framework Boot 2.4.4
Desktop 4.2.4
also see GitHub - Wayne-P/graph: Kotlin Neo4j Graph Issue
Possibly related to NullPointerException when persisting Kotlin data class · Issue #2141 · spring-projects/spring-data-neo4j · GitHub ,
possibly related to Return related objects with ids set after save · Issue #2148 · spring-projects/spring-data-neo4j · GitHub ,
probably related to something I am overlooking owing to an Easter hangover.
So we have three classes imaginatively labelled A, B & C
@Node ("NODE_A")
data class A constructor(
@Id @GeneratedValue val id: Long? = null, val aName: String, @Relationship(type = "A_TO_B_REL") val b: B, @Relationship(type = "A_TO_C_REL") val c: C
)
@Node ("NODE_B")
data class B constructor(
@Id @GeneratedValue val id: Long? = null, val bName:String, @Relationship(type = "B_TO_C_REL") val cList: List<C>
)
@Node("NODE_C")
data class C constructor(
@Id @GeneratedValue val id: Long? = null, val cName: String
)
So, roughly A has a B and a C.
B has a list of C .
So far, so good.
The application code ...
@Transactional
@SpringBootApplication
class GraphApplication {
@Bean
fun init(aRepository: ARepository, bRepository: BRepository, cRepository: CRepository): CommandLineRunner {
return CommandLineRunner {
val c1 = C(cName = "c1")
val c2 = C(cName = "c2")
val b1 = B(bName = "b1", cList = listOf(c1, c2))
val a1 = A(aName = "a1", b = b1, c = c1)
aRepository.deleteAll()
bRepository.deleteAll()
cRepository.deleteAll()
aRepository.save<A>(a1)
}
}
}
fun main(args: Array<String>) {
runApplication<GraphApplication>(*args)
}
Now curiously, repeated efforts to execute this code give different results.
Sometimes, an IllegalStateExcexception from the save attempt of
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:809) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:790) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1313) ~[spring-boot-2.4.4.jar:2.4.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[spring-boot-2.4.4.jar:2.4.4]
at aoni.graph.GraphApplicationKt.main(GraphApplication.kt:39) ~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.4.4.jar:2.4.4]
Caused by: java.util.NoSuchElementException: No value present
at java.base/java.util.Optional.get(Optional.java:148) ~[na:na]
Other times, the code runs without exception to produce two c1s with different ids
I appreciate that work is still being done in 2148 to ensure that ids of subcomponents are correctly returned in response to a save, but will this work lead to one c1 being created here ?
Or, as I suspect, should I be blaming the acetyldehyde here ?
Many thanks for any enlightenment.