Interface JpaRepository<T,ID>

All Superinterfaces:
org.springframework.data.repository.CrudRepository<T,ID>, org.springframework.data.repository.ListCrudRepository<T,ID>, org.springframework.data.repository.ListPagingAndSortingRepository<T,ID>, org.springframework.data.repository.PagingAndSortingRepository<T,ID>, org.springframework.data.repository.query.QueryByExampleExecutor<T>, org.springframework.data.repository.Repository<T,ID>
All Known Subinterfaces:
EnversRevisionRepository<T,ID,N>, JpaRepositoryImplementation<T,ID>
All Known Implementing Classes:
QuerydslJpaRepository, SimpleJpaRepository

@NoRepositoryBean public interface JpaRepository<T,ID> extends org.springframework.data.repository.ListCrudRepository<T,ID>, org.springframework.data.repository.ListPagingAndSortingRepository<T,ID>, org.springframework.data.repository.query.QueryByExampleExecutor<T>
JPA specific extension of Repository.
Author:
Oliver Gierke, Christoph Strobl, Mark Paluch, Sander Krabbenborg, Jesse Wouters, Greg Turnquist, Jens Schauder
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deletes the entities identified by the given ids using a single query.
    void
    Deletes all entities in a batch call.
    void
    Deletes the given entities in a batch which means it will create a single query.
    default void
    Deprecated.
    <S extends T>
    List<S>
    findAll(org.springframework.data.domain.Example<S> example)
     
    <S extends T>
    List<S>
    findAll(org.springframework.data.domain.Example<S> example, org.springframework.data.domain.Sort sort)
     
    void
    Flushes all pending changes to the database.
    getById(ID id)
    Deprecated.
    getOne(ID id)
    Deprecated.
    Returns a reference to the entity with the given identifier.
    <S extends T>
    List<S>
    Saves all entities and flushes changes instantly.
    <S extends T>
    S
    saveAndFlush(S entity)
    Saves an entity and flushes changes instantly.

    Methods inherited from interface org.springframework.data.repository.CrudRepository

    count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAll, findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Method Details

    • flush

      void flush()
      Flushes all pending changes to the database.
    • saveAndFlush

      <S extends T> S saveAndFlush(S entity)
      Saves an entity and flushes changes instantly.
      Parameters:
      entity - entity to be saved. Must not be null.
      Returns:
      the saved entity
    • saveAllAndFlush

      <S extends T> List<S> saveAllAndFlush(Iterable<S> entities)
      Saves all entities and flushes changes instantly.
      Parameters:
      entities - entities to be saved. Must not be null.
      Returns:
      the saved entities
      Since:
      2.5
    • deleteInBatch

      @Deprecated default void deleteInBatch(Iterable<T> entities)
      Deprecated.
      Deletes the given entities in a batch which means it will create a single query. This kind of operation leaves JPAs first level cache and the database out of sync. Consider flushing the EntityManager before calling this method.
      Parameters:
      entities - entities to be deleted. Must not be null.
    • deleteAllInBatch

      void deleteAllInBatch(Iterable<T> entities)
      Deletes the given entities in a batch which means it will create a single query. This kind of operation leaves JPAs first level cache and the database out of sync. Consider flushing the EntityManager before calling this method.

      It will also NOT honor cascade semantics of JPA, nor will it emit JPA lifecycle events.

      Parameters:
      entities - entities to be deleted. Must not be null.
      Since:
      2.5
    • deleteAllByIdInBatch

      void deleteAllByIdInBatch(Iterable<ID> ids)
      Deletes the entities identified by the given ids using a single query. This kind of operation leaves JPAs first level cache and the database out of sync. Consider flushing the EntityManager before calling this method.
      Parameters:
      ids - the ids of the entities to be deleted. Must not be null.
      Since:
      2.5
    • deleteAllInBatch

      void deleteAllInBatch()
      Deletes all entities in a batch call.
    • getOne

      @Deprecated T getOne(ID id)
      Deprecated.
      Returns a reference to the entity with the given identifier. Depending on how the JPA persistence provider is implemented this is very likely to always return an instance and throw an EntityNotFoundException on first access. Some of them will reject invalid identifiers immediately.
      Parameters:
      id - must not be null.
      Returns:
      a reference to the entity with the given identifier.
      See Also:
      • for details on when an exception is thrown.
    • getById

      @Deprecated T getById(ID id)
      Deprecated.
      Returns a reference to the entity with the given identifier. Depending on how the JPA persistence provider is implemented this is very likely to always return an instance and throw an EntityNotFoundException on first access. Some of them will reject invalid identifiers immediately.
      Parameters:
      id - must not be null.
      Returns:
      a reference to the entity with the given identifier.
      Since:
      2.5
      See Also:
      • for details on when an exception is thrown.
    • getReferenceById

      T getReferenceById(ID id)
      Returns a reference to the entity with the given identifier. Depending on how the JPA persistence provider is implemented this is very likely to always return an instance and throw an EntityNotFoundException on first access. Some of them will reject invalid identifiers immediately.
      Parameters:
      id - must not be null.
      Returns:
      a reference to the entity with the given identifier.
      Since:
      2.7
      See Also:
      • for details on when an exception is thrown.
    • findAll

      <S extends T> List<S> findAll(org.springframework.data.domain.Example<S> example)
      Specified by:
      findAll in interface org.springframework.data.repository.query.QueryByExampleExecutor<T>
    • findAll

      <S extends T> List<S> findAll(org.springframework.data.domain.Example<S> example, org.springframework.data.domain.Sort sort)
      Specified by:
      findAll in interface org.springframework.data.repository.query.QueryByExampleExecutor<T>