Interface ResultSetMapping<T>

All Known Implementing Classes:
ColumnMapping, CompoundMapping, ConstructorMapping, EntityMapping, TupleMapping

public sealed interface ResultSetMapping<T> permits CompoundMapping, TupleMapping, EntityMapping<T>, ConstructorMapping<T>, ColumnMapping<T>
Specifies a mapping of the columns of a result set of a SQL query or stored procedure to entities, scalar values, and Java class constructors.

A ResultSetMapping may be instantiated programmatically, for example:

 import static jakarta.persistence.sql.ResultSetMapping.*;

 ...

 var entityMapping =
         entity(Author.class,
                 field(Author_.ssn, "auth_ssn"),
                 embedded(Author_.name,
                         field(Name_.first, "auth_first_name"),
                         field(Name_.last, "auth_last_name")));

 var constructorMapping =
         constructor(Summary.class,
                 column("isbn", String.class),
                 column("title", String.class),
                 column("author", String.class));

 var compoundMapping =
         compound(
                 entity(Author.class),
                 entity(Book.class, field(Book_.isbn, "isbn")),
                 column("sales", BigDecimal.class),
                 constructor(Summary.class, column("isbn"), column("title"))
         );

Alternatively, an instance representing a result set mapping defined using annotations may be obtained via EntityManagerFactory.getResultSetMappings(Class).

A ResultSetMapping may be used to obtain and execute a TypedQuery.

Since:
4.0
See Also:
  • Method Details

    • type

      Class<T> type()
      The result type of the mapping.
    • column

      static <T> ColumnMapping<T> column(String columnName, Class<T> type)
      Construct a mapping for a single column to a scalar value.
      Parameters:
      columnName - The colum name
      type - The Java type of the scalar value
      See Also:
    • column

      static ColumnMapping<Object> column(String columnName)
      Construct a mapping for a single column to a scalar value.
      Parameters:
      columnName - The colum name
      See Also:
    • constructor

      static <T> ConstructorMapping<T> constructor(Class<T> targetClass, MappingElement<?>... arguments)
      Construct a mapping to a constructor of a Java class.
      Parameters:
      targetClass - The Java class which declares the constructor
      arguments - Mappings for the constructor parameters, in order
      See Also:
    • compound

      static CompoundMapping compound(MappingElement<?>... elements)
      Construct a mapping which packages a tuple of values as a Java array.
      Parameters:
      elements - Mappings for elements of the type
    • tuple

      static TupleMapping tuple(MappingElement<?>... elements)
      Construct a mapping which packages a tuple of values as an instance of Tuple.
      Parameters:
      elements - Mappings for elements of the type
    • entity

      @SafeVarargs static <T> EntityMapping<T> entity(Class<T> entityClass, MemberMapping<T>... fields)
      Construct a mapping for an entity class.
      Parameters:
      entityClass - The Java class of the entity
      fields - Mappings for fields or properties of the entity
      See Also:
    • entity

      @SafeVarargs static <T> EntityMapping<T> entity(Class<T> entityClass, String discriminatorColumn, MemberMapping<T>... fields)
      Construct a mapping for an entity class.
      Parameters:
      entityClass - The Java class of the entity
      discriminatorColumn - The name of the column holding the discriminator; an empty string indicates that there is no discriminator column
      fields - Mappings for fields or properties of the entity
      See Also:
    • entity

      @SafeVarargs static <T> EntityMapping<T> entity(Class<T> entityClass, LockModeType lockMode, String discriminatorColumn, MemberMapping<T>... fields)
      Construct a mapping for an entity class.
      Parameters:
      entityClass - The Java class of the entity
      lockMode - The lock mode acquired by SQL query
      discriminatorColumn - The name of the column holding the discriminator; an empty string indicates that there is no discriminator column
      fields - Mappings for fields or properties of the entity
      See Also:
    • embedded

      @SafeVarargs static <C,T> EmbeddedMapping<C,T> embedded(Class<C> container, Class<T> embeddableClass, String name, MemberMapping<T>... fields)
      Construct a mapping for an embedded object.
      Parameters:
      container - The Java class which declares the field holding the embedded object
      embeddableClass - The Java class of the embedded object
      name - The name of the field holding the embedded object
      fields - Mappings for fields or properties of the entity
    • embedded

      @SafeVarargs static <C,T> EmbeddedMapping<C,T> embedded(SingularAttribute<C,T> embedded, MemberMapping<T>... fields)
      Construct a mapping for an embedded object.
      Parameters:
      embedded - The metamodel attribute representing the field or property holding the embedded object
      fields - Mappings for fields or properties of the entity
    • field

      static <C,T> FieldMapping<C,T> field(Class<C> container, Class<T> type, String name, String columnName)
      Construct a mapping for a field or property of an entity or embeddable type.
      Parameters:
      container - The Java class which declares the field or property
      type - The type of the field or property
      name - The name of the field or property
      columnName - The name of the mapped column
      See Also:
    • field

      static <C,T> FieldMapping<C,T> field(SingularAttribute<C,T> attribute, String columnName)
      Construct a mapping for a field or property of an entity or embeddable type.
      Parameters:
      attribute - The metamodel attribute representing the field or property
      columnName - The name of the mapped column
      See Also: