Interface ResultSetMapping<T>
- Type Parameters:
T- The result type of the mapping
- 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 Summary
Modifier and TypeMethodDescriptionstatic ColumnMapping<Object> Construct a mapping for a single column to a scalar value.static <T> ColumnMapping<T> Construct a mapping for a single column to a scalar value.static CompoundMappingcompound(MappingElement<?>... elements) Construct a mapping which packages a tuple of values as a Java array.static <T> ConstructorMapping<T> constructor(Class<T> targetClass, MappingElement<?>... arguments) Construct a mapping to a constructor of a Java class.static <C,T> EmbeddedMapping <C, T> embedded(SingularAttribute<? super C, T> embedded, MemberMapping<T>... fields) Construct a mapping for an embedded object.static <C,T> EmbeddedMapping <C, T> embedded(Class<? super C> container, Class<T> embeddableClass, String name, MemberMapping<T>... fields) Construct a mapping for an embedded object.static <T> EntityMapping<T> entity(Class<T> entityClass, MemberMapping<T>... fields) Construct a mapping for an entity class.static <T> EntityMapping<T> entity(Class<T> entityClass, String discriminatorColumn, MemberMapping<? extends T>... fields) Construct a mapping for an entity class.static <C,T> FieldMapping <C, T> field(SingularAttribute<? super C, T> attribute, String columnName) Construct a mapping for a field or property of an entity or embeddable type.static <C,T> FieldMapping <C, T> Construct a mapping for a field or property of an entity or embeddable type.static TupleMappingtuple(MappingElement<?>... elements) Construct a mapping which packages a tuple of values as an instance ofTuple.type()The result type of the mapping.
-
Method Details
-
type
-
column
Construct a mapping for a single column to a scalar value.- Type Parameters:
T- The type of the scalar value- Parameters:
columnName- The colum nametype- The Java type of the scalar value- See Also:
-
column
Construct a mapping for a single column to a scalar value.- Parameters:
columnName- The colum name- See Also:
-
constructor
@Nonnull static <T> ConstructorMapping<T> constructor(@Nonnull Class<T> targetClass, @Nonnull MappingElement<?>... arguments) Construct a mapping to a constructor of a Java class.- Type Parameters:
T- The type of the Java class- Parameters:
targetClass- The Java class which declares the constructorarguments- Mappings for the constructor parameters, in order- See Also:
-
compound
Construct a mapping which packages a tuple of values as a Java array.- Parameters:
elements- Mappings for elements of the type
-
tuple
Construct a mapping which packages a tuple of values as an instance ofTuple.- Parameters:
elements- Mappings for elements of the type
-
entity
@Nonnull @SafeVarargs static <T> EntityMapping<T> entity(@Nonnull Class<T> entityClass, @Nonnull MemberMapping<T>... fields) Construct a mapping for an entity class.- Type Parameters:
T- The entity type- Parameters:
entityClass- The Java class of the entityfields- Mappings for fields or properties of the entity- See Also:
-
entity
@Nonnull @SafeVarargs static <T> EntityMapping<T> entity(@Nonnull Class<T> entityClass, @Nonnull String discriminatorColumn, @Nonnull MemberMapping<? extends T>... fields) Construct a mapping for an entity class.- Type Parameters:
T- The entity type- Parameters:
entityClass- The Java class of the entitydiscriminatorColumn- The name of the column holding the discriminator; an empty string indicates that there is no discriminator columnfields- Mappings for fields or properties of the entity and of its entity subclasses- See Also:
-
embedded
@Nonnull @SafeVarargs static <C,T> EmbeddedMapping<C,T> embedded(@Nonnull Class<? super C> container, @Nonnull Class<T> embeddableClass, @Nonnull String name, MemberMapping<T>... fields) Construct a mapping for an embedded object.- Type Parameters:
C- The container typeT- The embeddable type- Parameters:
container- The Java class which declares the field holding the embedded objectembeddableClass- The Java class of the embedded objectname- The name of the field holding the embedded objectfields- Mappings for fields or properties of the entity
-
embedded
@Nonnull @SafeVarargs static <C,T> EmbeddedMapping<C,T> embedded(@Nonnull SingularAttribute<? super C, T> embedded, @Nonnull MemberMapping<T>... fields) Construct a mapping for an embedded object.- Type Parameters:
C- The container typeT- The embeddable type- Parameters:
embedded- The metamodel attribute representing the field or property holding the embedded objectfields- Mappings for fields or properties of the entity
-
field
@Nonnull static <C,T> FieldMapping<C,T> field(@Nonnull Class<? super C> container, @Nonnull Class<T> type, @Nonnull String name, @Nonnull String columnName) Construct a mapping for a field or property of an entity or embeddable type.- Type Parameters:
C- The type of the entity or embeddable typeT- The type of the field or property- Parameters:
container- The Java class which declares the field or propertytype- The type of the field or propertyname- The name of the field or propertycolumnName- The name of the mapped column- See Also:
-
field
static <C,T> FieldMapping<C,T> field(@Nonnull SingularAttribute<? super C, T> attribute, @Nonnull String columnName) Construct a mapping for a field or property of an entity or embeddable type.- Type Parameters:
C- The type of the entity or embeddable typeT- The type of the field or property- Parameters:
attribute- The metamodel attribute representing the field or propertycolumnName- The name of the mapped column- See Also:
-