Package org.hibernate

Record Class BatchSize

java.lang.Object
java.lang.Record
org.hibernate.BatchSize
Record Components:
batchSize - The batch size
All Implemented Interfaces:
FindOption

public record BatchSize(int batchSize) extends Record implements FindOption
Specify a batch size, that is, how many entities should be fetched in each request to the database, for an invocation of Session.findMultiple(Class, List, FindOption...).
  • By default, the batch sizing strategy is determined by the SQL dialect, but
  • if some batchSize>1 is specified as an argument to this method, then that batch size will be used.

If an explicit batch size is set manually, care should be taken to not exceed the capabilities of the underlying database.

The performance impact of setting a batch size depends on whether a SQL array may be used to pass the list of identifiers to the database:

  • for databases which support standard SQL arrays, a smaller batch size might be extremely inefficient compared to a very large batch size or no batching at all, but
  • on the other hand, for databases with no SQL array type, a large batch size results in long SQL statements with many JDBC parameters.

    A batch size is considered a hint. This option has no effect on EntityManager.find(Class, Object, FindOption...).

Since:
7.0
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    BatchSize(int batchSize)
    Creates an instance of a BatchSize record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the value of the batchSize record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • BatchSize

      public BatchSize(int batchSize)
      Creates an instance of a BatchSize record class.
      Parameters:
      batchSize - the value for the batchSize record component
  • Method Details

    • 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 '=='.
      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.
    • batchSize

      public int batchSize()
      Returns the value of the batchSize record component.
      Returns:
      the value of the batchSize record component