Enum Class Embeddable.EmbeddableType

java.lang.Object
java.lang.Enum<Embeddable.EmbeddableType>
jakarta.nosql.Embeddable.EmbeddableType
All Implemented Interfaces:
Serializable, Comparable<Embeddable.EmbeddableType>, Constable
Enclosing class:
Embeddable

public static enum Embeddable.EmbeddableType extends Enum<Embeddable.EmbeddableType>
Defines the strategies for how fields of an embeddable class are stored in the database. An embeddable class can have two types of strategies for how its fields are stored:
  • FLAT: The fields of the embeddable class are embedded directly into the data structure of the parent entity or embeddable, without creating a nested structure in the database.
  • GROUPING: The fields of the embeddable class are stored in a structured type, such as a user-defined type (UDT), where the fields are grouped together under a single object or nested structure within the parent entity.

The FLAT strategy ensures that the embeddable class fields are directly mapped to the database schema of the parent entity, whereas the GROUPING strategy results in the embeddable fields being treated as a distinct structure that may be stored in a separate sub-schema (like a UDT or nested document), depending on the NoSQL database used.

While the FLAT strategy is guaranteed to be supported by all Jakarta NoSQL implementations, the support for the GROUPING strategy may vary between NoSQL databases. If a NoSQL database does not support it, invoking operations requiring the GROUPING strategy may result in an UnsupportedOperationException. Additionally, if a database requires specific configurations, such as the Column.udt() attribute, and those configurations are not met, a MappingException may be thrown.

Example use case of the enum values:

@Embeddable(EmbeddableType.FLAT)
public class Address {
    @Column
    private String street;
    @Column
    private String city;
}

@Embeddable(EmbeddableType.GROUPING)
public class Address {
    @Column
    private String street;
    @Column
    private String city;
}
Since:
1.0.0
  • Enum Constant Details

    • FLAT

      public static final Embeddable.EmbeddableType FLAT
      Fields of the embeddable class are embedded directly into the data structure of the parent entity or embeddable.

      This is the default behavior when using Embeddable without specifying a type.

      Example:

      @Entity
      public class Person {
      
          @Id
          private String id;
      
          @Column
          private String name;
      
          @Column
          private Address address;
      }
      
      @Embeddable
      public class Address {
      
          @Column
          private String street;
      
          @Column
          private String city;
      }
      

      Illustrative structure with FLAT embedding:

      {
        "id": "p1",
        "name": "Ada",
        "street": "123 Main St",
        "city": "Leiria"
      }
      

      This representation illustrates how the embedded fields are flattened into the parent. Actual persistence formats may vary depending on the NoSQL database provider.

    • GROUPING

      public static final Embeddable.EmbeddableType GROUPING
      Fields of the embeddable class are stored in a grouped structure, such as a user-defined type (UDT) or embedded document.

      This mode is used to encapsulate the embeddable fields under a single object inside the parent structure.

      Example:

       @Entity
       public class Person {
      
           @Id
           private String id;
      
           @Column
           private String name;
      
           @Column
           private Address address;
       }
      
       @Embeddable(EmbeddableType.GROUPING)
       public class Address {
      
           @Column
           private String street;
      
           @Column
           private String city;
       }
       

      Illustrative structure with GROUPING embedding:

       {
         "id": "p1",
         "name": "Ada",
         "address": {
           "street": "123 Main St",
           "city": "Leiria"
         }
       }
       

      This nested structure is representative and does not assume a specific serialization format like JSON. Each database provider may map this structure differently depending on its capabilities.

  • Method Details

    • values

      public static Embeddable.EmbeddableType[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Embeddable.EmbeddableType valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null