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 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<C, T> embedded, MemberMapping<T>... fields) Construct a mapping for an embedded object.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.static <T> EntityMapping<T> entity(Class<T> entityClass, LockModeType lockMode, String discriminatorColumn, MemberMapping<T>... fields) Construct a mapping for an entity class.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<T>... fields) Construct a mapping for an entity class.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.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.- 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
Construct a mapping to a constructor of a 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
Construct a mapping for an entity class.- Parameters:
entityClass- The Java class of the entityfields- 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 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- 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 entitylockMode- The lock mode acquired by SQL querydiscriminatorColumn- 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- 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 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
@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 objectfields- 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 propertytype- The type of the field or propertyname- The name of the field or propertycolumnName- The name of the mapped column- See Also:
-
field
Construct a mapping for a field or property of an entity or embeddable type.- Parameters:
attribute- The metamodel attribute representing the field or propertycolumnName- The name of the mapped column- See Also:
-