Record Class ColumnMapping<T>

java.lang.Object
java.lang.Record
jakarta.persistence.sql.ColumnMapping<T>
Type Parameters:
T - The type of the resulting scalar value
Record Components:
columnName - The name of the mapped column of the result set
type - The Java type of the resulting scalar value
alias - An optional alias
All Implemented Interfaces:
MappingElement<T>, ResultSetMapping<T>, TupleElement<T>

public record ColumnMapping<T>(@Nonnull String columnName, @Nonnull Class<T> type, @Nullable String alias) extends Record implements MappingElement<T>, ResultSetMapping<T>
Maps a column of a JDBC ResultSet to a scalar value in the result returned by the query.
Since:
4.0
See Also:
  • Constructor Details

    • ColumnMapping

      public ColumnMapping(@Nonnull String columnName, @Nonnull Class<T> type, @Nullable String alias)
      Creates an instance of a ColumnMapping record class.
      Parameters:
      columnName - the value for the columnName record component
      type - the value for the type record component
      alias - the value for the alias record component
  • Method Details

    • getJavaType

      @Nonnull public Class<T> getJavaType()
      The Java type of the scalar value.
      Specified by:
      getJavaType in interface TupleElement<T>
      Returns:
      the Java type of the tuple element
    • getAlias

      @Nullable public String getAlias()
      The colum name.
      Specified by:
      getAlias in interface TupleElement<T>
      Returns:
      alias
    • withAlias

      @Nonnull public ColumnMapping<T> withAlias(@Nonnull String alias)
      Specify an alias for this column in the result set.
      Specified by:
      withAlias in interface MappingElement<T>
      Parameters:
      alias - The alias
    • of

      @Nonnull public static ColumnMapping<Object> of(@Nonnull String columnName)
      Construct a new instance.
      Parameters:
      columnName - The name of the mapped column of the result set
    • of

      @Nonnull public static <T> ColumnMapping<T> of(@Nonnull String columnName, @Nonnull Class<T> type)
      Construct a new instance.
      Type Parameters:
      T - The type of the resulting scalar value
      Parameters:
      columnName - The name of the mapped column of the result set
      type - The Java type of the resulting scalar value
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • columnName

      @Nonnull public String columnName()
      Returns the value of the columnName record component.
      Returns:
      the value of the columnName record component
    • type

      @Nonnull public Class<T> type()
      Returns the value of the type record component.
      Specified by:
      type in interface ResultSetMapping<T>
      Returns:
      the value of the type record component
    • alias

      @Nullable public String alias()
      Returns the value of the alias record component.
      Returns:
      the value of the alias record component