Add `@Transient` properties to `PersistentEntity` and use value defaulting for transient constructor properties
We now maintain @Transient metadata in the mapping model to determine whether a transient property has been used in a Kotlin Data class, Record or plain Java class.
record MyRecord(String firstname, @Transient String lastname) {
}
data class MyDataClass(@Transient val firstname: String = "foo", @Transient val age: Int)
Entity instantiation populates properties with default values (null for object types, or primitive default values) so that Kotlin data classes can use defaulting.
Closes #1432 Closes #2942
Do we really need getTransientProperty(…)? I wonder what the use case is to actually look up those explicitly? Also, dies that mean that getProperty(…) only returns non-transient properties now?
One other thing we have to double-check is the expectations that client code using doWithProperties(…) had. So far, the callback was not involved for transient properties, simply because they haven't been captured at all. Unfortunately, this means that the code in those callbacks doesn't expect to be called for transient properties in the first place and doesn't guard against that case.
One other thing we have to double-check is the expectations that client code using doWithProperties(…) had
We never provided transient properties to callbacks via doWithProperties and I would not want to change that. Otherwise, a lot of code assumptions get broken.
Likely we don't need to expose getTransientProperty(…). This is merely used internally for the isTransient check.
Also, dies that mean that getProperty(…) only returns non-transient properties now?
getProperty never returned transient properties in the first place. It's intended to remain that way.
public void treatsTransientAsNotExisting() {
assertThat(getProperty(ClassWithReadOnlyProperties.class, "transientProperty")).isNull();
}