Skip to content

Files

Latest commit

e4429a2 · Nov 10, 2023

History

History
This branch is 14 commits ahead of, 18 commits behind scylladb/java-driver:scylla-4.x.

record

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Nov 10, 2023

Java 14 Records

Java 14 introduced Record as a lightweight, immutable alternative to POJOs. You can map annotated records as entities.

We have a full example at DataStax-Examples/object-mapper-jvm/record.

Note: records are a preview feature of Java 14. As such the mapper's support for them is also provided as a preview.

Writing the model

Annotate your records like regular classes:

@Entity
record Product(@PartitionKey int id, String description) {}

Records are immutable and use the fluent getter style, but you don't need to declare that explicitly with @PropertyStrategy: the mapper detects when it's processing a record, and will assume mutable = false, getterStyle = FLUENT by default.

Building

You need to build with Java 14, and pass the --enable-preview flag to both the compiler and the runtime JVM. See pom.xml in the example.