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 Summary
Modifier and TypeMethodDescriptionvoid
deleteAllByIdInBatch
(Iterable<ID> ids) Deletes the entities identified by the given ids using a single query.void
Deletes all entities in a batch call.void
deleteAllInBatch
(Iterable<T> entities) Deletes the given entities in a batch which means it will create a single query.default void
deleteInBatch
(Iterable<T> entities) Deprecated.void
flush()
Flushes all pending changes to the database.Deprecated.usegetReferenceById(ID)
instead.Deprecated.usegetReferenceById(ID)
instead.getReferenceById
(ID id) Returns a reference to the entity with the given identifier.saveAllAndFlush
(Iterable<S> entities) Saves all entities and flushes changes instantly.<S extends T>
SsaveAndFlush
(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
-
Method Details
-
flush
void flush()Flushes all pending changes to the database. -
saveAndFlush
Saves an entity and flushes changes instantly.- Parameters:
entity
- entity to be saved. Must not be null.- Returns:
- the saved entity
-
saveAllAndFlush
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.UsedeleteAllInBatch(Iterable)
instead.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 theEntityManager
before calling this method.- Parameters:
entities
- entities to be deleted. Must not be null.
-
deleteAllInBatch
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 theEntityManager
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
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 theEntityManager
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.usegetReferenceById(ID)
instead.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 anEntityNotFoundException
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.usegetReferenceById(ID)
instead.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 anEntityNotFoundException
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
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 anEntityNotFoundException
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
- Specified by:
findAll
in interfaceQueryByExampleExecutor<T>
-
findAll
- Specified by:
findAll
in interfaceQueryByExampleExecutor<T>
-
deleteAllInBatch(Iterable)
instead.