micronaut-data
micronaut-data copied to clipboard
Keep relationships of entity returned by saveReturning
Feature description
As discussed in #2694 an entity returned by saveReturning()
are created based on the result of executed insert
query only. Already present relationships of the entity will be removed/ignored.
To match the behavior of the "default" save()
method, the relationships of the entity should be returned.
Taking the following entity (from this example application):
@Serdeable
@MappedEntity
data class Event(
@field:Id
@field:GeneratedValue
val id: Long? = null,
@field:Version
val version: Long? = null,
@field:GeneratedValue
val createdAt: LocalDateTime? = null,
val property: String,
@Relation(value = Relation.Kind.MANY_TO_ONE)
val child: Child? = null,
)
And the following snippet:
val child = childRepository.save(Child(value = "child3"))
val event = eventRepository.saveReturning(Event(property = "test", child = child))
I would expect event.child
to be not null.