Interface JpaRepository<T,ID>

All Superinterfaces:
CrudRepository<T,ID>, ListCrudRepository<T,ID>, ListPagingAndSortingRepository<T,ID>, PagingAndSortingRepository<T,ID>, QueryByExampleExecutor<T>, 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 ListCrudRepository<T,ID>, ListPagingAndSortingRepository<T,ID>, QueryByExampleExecutor<T>
JPA specific extension of Repository.
Author:
Oliver Gierke, Christoph Strobl, Mark Paluch, Sander Krabbenborg, Jesse Wouters, Greg Turnquist, Jens Schauder
  • 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(Example<S> example)
      Specified by:
      findAll in interface QueryByExampleExecutor<T>
    • findAll

      <S extends T> List<S> findAll(Example<S> example, Sort sort)
      Specified by:
      findAll in interface QueryByExampleExecutor<T>