Record Class TypedParameterValue<J>

java.lang.Object
java.lang.Record
org.hibernate.query.TypedParameterValue<J>

public record TypedParameterValue<J>(BindableType<J> type, J value) extends Record
Represents a typed argument to a query parameter.

Usually, the Hibernate type of an argument to a query parameter may be inferred, and so it's rarely necessary to explicitly pass a type when binding the argument. Occasionally, and especially when the argument is null, the type cannot be inferred and must be explicitly specified. In such cases, an instance of TypedParameterValue may be passed to setParameter().

For example:

 query.setParameter("stringNamedParam",
         TypedParameterValue.ofNull(StandardBasicTypes.STRING))
 
 query.setParameter("address",
         TypedParameterValue.of(Address_.class_, address))
 

Here, a "null string" argument was bound to the named parameter :stringNamedParam.

Since:
6
See Also:
  • Constructor Details

    • TypedParameterValue

      public TypedParameterValue(BindableType<J> type, J value)
      Creates an instance of a TypedParameterValue record class.
      Parameters:
      type - the value for the type record component
      value - the value for the value record component
  • Method Details

    • of

      public static <J> TypedParameterValue<J> of(Type<J> type, J value)
      Obtain an instance with the given type and given value.
      Since:
      7.0
    • ofNull

      public static <J> TypedParameterValue<J> ofNull(Type<J> type)
      Obtain an instance with the given type and a null value.
      Since:
      7.0
    • getValue

      @Deprecated(since="7") public J getValue()
      Deprecated.
      use value
      The value to bind
      Returns:
      The value to be bound
    • getType

      @Deprecated(since="7") public BindableType<J> getType()
      Deprecated.
      use type
      The specific Hibernate type to use to bind the value.
      Returns:
      The Hibernate type to use.
    • getTypeReference

      @Deprecated(since="7") public BasicTypeReference<J> getTypeReference()
      Deprecated.
      use type
      The specific Hibernate type reference to use to bind the value.
      Returns:
      The Hibernate type reference to use.
    • 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.
    • type

      public BindableType<J> type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • value

      public J value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component