T - the type of the entity to handleID - the type of the entity's identifier@Repository @Transactional(readOnly=true) public class SimpleJpaRepository<T,ID> extends Object implements JpaRepositoryImplementation<T,ID>
CrudRepository interface. This will offer
you a more sophisticated interface than the plain EntityManager .| Constructor and Description |
|---|
SimpleJpaRepository(Class<T> domainClass,
javax.persistence.EntityManager em)
Creates a new
SimpleJpaRepository to manage objects of the given domain type. |
SimpleJpaRepository(JpaEntityInformation<T,?> entityInformation,
javax.persistence.EntityManager entityManager)
Creates a new
SimpleJpaRepository to manage objects of the given JpaEntityInformation. |
| Modifier and Type | Method and Description |
|---|---|
long |
count() |
<S extends T> |
count(Example<S> example) |
long |
count(Specification<T> spec)
Returns the number of instances that the given
Specification will return. |
void |
delete(T entity) |
void |
deleteAll() |
void |
deleteAll(Iterable<? extends T> entities) |
void |
deleteAllInBatch()
Deletes all entities in a batch call.
|
void |
deleteById(ID id) |
void |
deleteInBatch(Iterable<T> entities)
Deletes the given entities in a batch which means it will create a single
Query. |
<S extends T> |
exists(Example<S> example) |
boolean |
existsById(ID id) |
List<T> |
findAll() |
<S extends T> |
findAll(Example<S> example) |
<S extends T> |
findAll(Example<S> example,
Pageable pageable) |
<S extends T> |
findAll(Example<S> example,
Sort sort) |
Page<T> |
findAll(Pageable pageable) |
List<T> |
findAll(Sort sort) |
List<T> |
findAll(Specification<T> spec)
Returns all entities matching the given
Specification. |
Page<T> |
findAll(Specification<T> spec,
Pageable pageable)
Returns a
Page of entities matching the given Specification. |
List<T> |
findAll(Specification<T> spec,
Sort sort)
Returns all entities matching the given
Specification and Sort. |
List<T> |
findAllById(Iterable<ID> ids) |
Optional<T> |
findById(ID id) |
<S extends T> |
findOne(Example<S> example) |
Optional<T> |
findOne(Specification<T> spec)
Returns a single entity matching the given
Specification or Optional.empty() if none found. |
void |
flush()
Flushes all pending changes to the database.
|
protected <S extends T> |
getCountQuery(Specification<S> spec,
Class<S> domainClass)
Creates a new count query for the given
Specification. |
protected javax.persistence.TypedQuery<Long> |
getCountQuery(Specification<T> spec)
Deprecated.
override
getCountQuery(Specification, Class) instead |
protected Class<T> |
getDomainClass() |
T |
getOne(ID id)
Returns a reference to the entity with the given identifier.
|
protected <S extends T> |
getQuery(Specification<S> spec,
Class<S> domainClass,
Pageable pageable)
Creates a new
TypedQuery from the given Specification. |
protected <S extends T> |
getQuery(Specification<S> spec,
Class<S> domainClass,
Sort sort)
|
protected javax.persistence.TypedQuery<T> |
getQuery(Specification<T> spec,
Pageable pageable)
Creates a new
TypedQuery from the given Specification. |
protected javax.persistence.TypedQuery<T> |
getQuery(Specification<T> spec,
Sort sort)
|
protected org.springframework.data.jpa.repository.support.QueryHints |
getQueryHints()
Returns
QueryHints with the query hints based on the current CrudMethodMetadata and potential
EntityGraph information. |
protected CrudMethodMetadata |
getRepositoryMethodMetadata() |
protected <S extends T> |
readPage(javax.persistence.TypedQuery<S> query,
Class<S> domainClass,
Pageable pageable,
Specification<S> spec)
|
protected Page<T> |
readPage(javax.persistence.TypedQuery<T> query,
Pageable pageable,
Specification<T> spec)
Deprecated.
|
<S extends T> |
save(S entity) |
<S extends T> |
saveAll(Iterable<S> entities) |
<S extends T> |
saveAndFlush(S entity)
Saves an entity and flushes changes instantly.
|
void |
setEscapeCharacter(EscapeCharacter escapeCharacter)
Configures the
EscapeCharacter to be used with the repository. |
void |
setRepositoryMethodMetadata(CrudMethodMetadata crudMethodMetadata)
Configures a custom
CrudMethodMetadata to be used to detect LockModeTypes and query hints to be
applied to queries. |
public SimpleJpaRepository(JpaEntityInformation<T,?> entityInformation, javax.persistence.EntityManager entityManager)
SimpleJpaRepository to manage objects of the given JpaEntityInformation.entityInformation - must not be null.entityManager - must not be null.public SimpleJpaRepository(Class<T> domainClass, javax.persistence.EntityManager em)
SimpleJpaRepository to manage objects of the given domain type.domainClass - must not be null.em - must not be null.public void setRepositoryMethodMetadata(CrudMethodMetadata crudMethodMetadata)
CrudMethodMetadata to be used to detect LockModeTypes and query hints to be
applied to queries.setRepositoryMethodMetadata in interface JpaRepositoryImplementation<T,ID>crudMethodMetadata - public void setEscapeCharacter(EscapeCharacter escapeCharacter)
JpaRepositoryImplementationEscapeCharacter to be used with the repository.setEscapeCharacter in interface JpaRepositoryImplementation<T,ID>escapeCharacter - Must not be null.@Nullable protected CrudMethodMetadata getRepositoryMethodMetadata()
@Transactional public void deleteById(ID id)
deleteById in interface CrudRepository<T,ID>@Transactional public void delete(T entity)
delete in interface CrudRepository<T,ID>@Transactional public void deleteAll(Iterable<? extends T> entities)
deleteAll in interface CrudRepository<T,ID>@Transactional public void deleteInBatch(Iterable<T> entities)
JpaRepositoryQuery. Assume that we will clear
the EntityManager after the call.deleteInBatch in interface JpaRepository<T,ID>@Transactional public void deleteAll()
deleteAll in interface CrudRepository<T,ID>@Transactional public void deleteAllInBatch()
JpaRepositorydeleteAllInBatch in interface JpaRepository<T,ID>public Optional<T> findById(ID id)
findById in interface CrudRepository<T,ID>protected org.springframework.data.jpa.repository.support.QueryHints getQueryHints()
QueryHints with the query hints based on the current CrudMethodMetadata and potential
EntityGraph information.public T getOne(ID id)
JpaRepositoryEntityNotFoundException on first access. Some of them will reject invalid identifiers
immediately.getOne in interface JpaRepository<T,ID>id - must not be null.for details on when an exception is thrown.public boolean existsById(ID id)
existsById in interface CrudRepository<T,ID>public List<T> findAll()
findAll in interface JpaRepository<T,ID>findAll in interface CrudRepository<T,ID>public List<T> findAllById(Iterable<ID> ids)
findAllById in interface JpaRepository<T,ID>findAllById in interface CrudRepository<T,ID>public List<T> findAll(Sort sort)
findAll in interface JpaRepository<T,ID>findAll in interface PagingAndSortingRepository<T,ID>public Page<T> findAll(Pageable pageable)
findAll in interface PagingAndSortingRepository<T,ID>public Optional<T> findOne(@Nullable Specification<T> spec)
JpaSpecificationExecutorSpecification or Optional.empty() if none found.findOne in interface JpaSpecificationExecutor<T>spec - can be null.public List<T> findAll(@Nullable Specification<T> spec)
JpaSpecificationExecutorSpecification.findAll in interface JpaSpecificationExecutor<T>spec - can be null.public Page<T> findAll(@Nullable Specification<T> spec, Pageable pageable)
JpaSpecificationExecutorPage of entities matching the given Specification.findAll in interface JpaSpecificationExecutor<T>spec - can be null.pageable - must not be null.public List<T> findAll(@Nullable Specification<T> spec, Sort sort)
JpaSpecificationExecutorSpecification and Sort.findAll in interface JpaSpecificationExecutor<T>spec - can be null.sort - must not be null.public <S extends T> Optional<S> findOne(Example<S> example)
findOne in interface QueryByExampleExecutor<T>public <S extends T> long count(Example<S> example)
count in interface QueryByExampleExecutor<T>public <S extends T> boolean exists(Example<S> example)
exists in interface QueryByExampleExecutor<T>public <S extends T> List<S> findAll(Example<S> example)
findAll in interface JpaRepository<T,ID>findAll in interface QueryByExampleExecutor<T>public <S extends T> List<S> findAll(Example<S> example, Sort sort)
findAll in interface JpaRepository<T,ID>findAll in interface QueryByExampleExecutor<T>public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable)
findAll in interface QueryByExampleExecutor<T>public long count()
count in interface CrudRepository<T,ID>public long count(@Nullable Specification<T> spec)
JpaSpecificationExecutorSpecification will return.count in interface JpaSpecificationExecutor<T>spec - the Specification to count instances for. Can be null.@Transactional public <S extends T> S save(S entity)
save in interface CrudRepository<T,ID>@Transactional public <S extends T> S saveAndFlush(S entity)
JpaRepositorysaveAndFlush in interface JpaRepository<T,ID>@Transactional public <S extends T> List<S> saveAll(Iterable<S> entities)
saveAll in interface JpaRepository<T,ID>saveAll in interface CrudRepository<T,ID>@Transactional public void flush()
JpaRepositoryflush in interface JpaRepository<T,ID>@Deprecated protected Page<T> readPage(javax.persistence.TypedQuery<T> query, Pageable pageable, @Nullable Specification<T> spec)
readPage(TypedQuery, Class, Pageable, Specification) insteadquery - must not be null.spec - can be null.pageable - must not be null.protected <S extends T> Page<S> readPage(javax.persistence.TypedQuery<S> query, Class<S> domainClass, Pageable pageable, @Nullable Specification<S> spec)
query - must not be null.domainClass - must not be null.spec - can be null.pageable - can be null.protected javax.persistence.TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pageable)
TypedQuery from the given Specification.spec - can be null.pageable - must not be null.protected <S extends T> javax.persistence.TypedQuery<S> getQuery(@Nullable Specification<S> spec, Class<S> domainClass, Pageable pageable)
TypedQuery from the given Specification.spec - can be null.domainClass - must not be null.pageable - must not be null.protected javax.persistence.TypedQuery<T> getQuery(@Nullable Specification<T> spec, Sort sort)
spec - can be null.sort - must not be null.protected <S extends T> javax.persistence.TypedQuery<S> getQuery(@Nullable Specification<S> spec, Class<S> domainClass, Sort sort)
spec - can be null.domainClass - must not be null.sort - must not be null.@Deprecated protected javax.persistence.TypedQuery<Long> getCountQuery(@Nullable Specification<T> spec)
getCountQuery(Specification, Class) insteadSpecification.spec - can be null.protected <S extends T> javax.persistence.TypedQuery<Long> getCountQuery(@Nullable Specification<S> spec, Class<S> domainClass)
Specification.spec - can be null.domainClass - must not be null.Copyright © 2011–2019 Pivotal Software, Inc.. All rights reserved.