# Class InsertBatchQuery

java.lang.Object
org.apache.cayenne.query.BatchQuery
org.apache.cayenne.query.InsertBatchQuery

All Implemented Interfaces:
  `Serializable, Query`

public class InsertBatchQuery extends BatchQuery
Batched INSERT query. Allows inserting multiple object snapshots (DataRows) for a given DbEntity in a single query. InsertBatchQuery normally is not used directly. Rather DataContext creates one internally when committing Persistent objects.

See Also:
  - Serialized Form

- ## Field Summary

  ### Fields inherited from class BatchQuery

  `dbAttributes, dbEntity, rows`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `InsertBatchQuery(DbEntity entity, int batchCapacity)`
  Creates new InsertBatchQuery for a given DbEntity and estimated capacity.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `add(Map<String,Object> snapshot)`
  Adds a snapshot to batch.
  `void`
  `add(Map<String,Object> snapshot, ObjectId id)`
  Adds a snapshot to batch.

  ### Methods inherited from class BatchQuery

  `createSQLAction, getDbAttributes, getDbEntity, getMetaData, getRows, isUsingOptimisticLocking, route`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### InsertBatchQuery

    public InsertBatchQuery(DbEntity entity, int batchCapacity)
    Creates new InsertBatchQuery for a given DbEntity and estimated capacity.

- ## Method Details

  - ### add

    public void add(Map<String,Object> snapshot)
    Adds a snapshot to batch. A shortcut for "add(snapshot, null)".

  - ### add

    public void add(Map<String,Object> snapshot, ObjectId id)
    Adds a snapshot to batch. Optionally stores the object id for the snapshot. Note that snapshot can hold either the real values or the instances of java.util.Supplier that will be resolved to the actual value when the row is bound to a PreparedStatement, thus allowing deferred propagated keys resolution.
    Since:
      1.2