You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit introduces support for Kotlin Value Classes which are designed for a more expressive domain model to make underlying concepts explicit. Spring Data can now read and write types that define properties using Value Classes.
The support covers reflection based instantiation of Kotlin inline class, nullability and defaulting permutations as well as value classes with generics.
Closes: #1947
Original Pull Request: #2866
Copy file name to clipboardexpand all lines: src/main/asciidoc/object-mapping.adoc
+24
Original file line number
Diff line number
Diff line change
@@ -436,3 +436,27 @@ You can exclude properties by annotating these with `@Transient`.
436
436
2. How to represent properties in your data store?
437
437
Using the same field/column name for different values typically leads to corrupt data so you should annotate least one of the properties using an explicit field/column name.
438
438
3. Using `@AccessType(PROPERTY)` cannot be used as the super-property cannot be set.
439
+
440
+
[[mapping.kotlin.value.classes]]
441
+
=== Kotlin Value Classes
442
+
443
+
Kotlin Value Classes are designed for a more expressive domain model to make underlying concepts explicit.
444
+
Spring Data can read and write types that define properties using Value Classes.
445
+
446
+
Consider the following domain model:
447
+
448
+
====
449
+
[source,kotlin]
450
+
----
451
+
@JvmInline
452
+
value class EmailAddress(val theAddress: String) <1>
453
+
454
+
data class Contact(val id: String, val name:String, val emailAddress: EmailAddress) <2>
455
+
----
456
+
457
+
<1> A simple value class with a non-nullable value type.
458
+
<2> Data class defining a property using the `EmailAddress` value class.
459
+
====
460
+
461
+
NOTE: Non-nullable properties using non-primitive value types are flattened in the compiled class to the value type.
462
+
Nullable primitive value types or nullable value-in-value types are represented with their wrapper type and that affects how value types are represented in the database.
0 commit comments