Annotation Type PropertyStrategy


  • @Target(TYPE)
    @Retention(RUNTIME)
    public @interface PropertyStrategy
    Annotates an Entity to customize certain aspects of the introspection process that determines which methods are considered as properties, and how new instances will be created.

    Example:

     @Entity
     @PropertyStrategy(getterStyle = FLUENT)
     public class Account {
       ...
     }
     
    This annotation can be inherited from an interface or parent class.

    When neither the entity class nor any of its parent is explicitly annotated, the mapper will assume context-dependent defaults:

    • for a Scala case class: mutable = false and getterStyle = FLUENT. The mapper detects this case by checking if the entity implements scala.Product.
    • for a Kotlin data class: mutable = false and getterStyle = JAVABEANS. The mapper detects this case by checking if the entity is annotated with kotlin.Metadata, and if it has any method named component1 (both of these are added automatically by the Kotlin compiler).
    • Java records (JDK 14 and above): mutable = false and getterStyle = FLUENT. The mapper detects this case by checking if the entity extends java.lang.Record.
    • any other case: mutable = true, getterStyle = JAVABEANS and setterStyle = JAVABEANS.
    Not that this only applies if the annotation is completely absent. If it is present with only some of its attributes, the remaining attributes will get the default declared by the annotation, not the context-dependent default above (for example, if a Kotlin data class is annotated with @PropertyStrategy(getterStyle = FLUENT), it will be mutable).
    • Element Detail

      • getterStyle

        GetterStyle getterStyle
        The style of getter. See GetterStyle and its constants for more explanations.
        Default:
        com.datastax.oss.driver.api.mapper.entity.naming.GetterStyle.JAVABEANS
      • setterStyle

        SetterStyle setterStyle
        The style of setter. See SetterStyle and its constants for more explanations.

        This has no effect if mutable() is false.

        Default:
        com.datastax.oss.driver.api.mapper.entity.naming.SetterStyle.JAVABEANS
      • mutable

        boolean mutable
        Whether the entity is mutable.

        If this is set to false:

        • the mapper won't try to discover setters for the properties;
        • it will assume that the entity class has a visible constructor that takes all the non-transient properties as arguments.
        Default:
        true