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 Serializable> extends Object implements JpaRepository<T,ID>, JpaSpecificationExecutor<T>
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(ID id) |
void |
delete(Iterable<? extends T> entities) |
void |
delete(T entity) |
void |
deleteAll() |
void |
deleteAllInBatch()
Deletes all entities in a batch call.
|
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 |
exists(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) |
List<T> |
findAll(Iterable<ID> ids) |
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. |
<S extends T> |
findOne(Example<S> example) |
T |
findOne(ID id) |
T |
findOne(Specification<T> spec)
Returns a single entity matching the given
Specification. |
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 Map<String,Object> |
getQueryHints()
Returns a
Map 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(Iterable<S> entities) |
<S extends T> |
save(S entity) |
<S extends T> |
saveAndFlush(S entity)
Saves an entity and flushes changes instantly.
|
void |
setEscapeCharacter(EscapeCharacter escapeCharacter) |
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.crudMethodMetadata - public void setEscapeCharacter(EscapeCharacter escapeCharacter)
protected CrudMethodMetadata getRepositoryMethodMetadata()
@Transactional public void delete(ID id)
delete in interface CrudRepository<T,ID extends Serializable>@Transactional public void delete(T entity)
delete in interface CrudRepository<T,ID extends Serializable>@Transactional public void delete(Iterable<? extends T> entities)
delete in interface CrudRepository<T,ID extends Serializable>@Transactional public void deleteInBatch(Iterable<T> entities)
JpaRepositoryQuery. Assume that we will clear
the EntityManager after the call.deleteInBatch in interface JpaRepository<T,ID extends Serializable>@Transactional public void deleteAll()
deleteAll in interface CrudRepository<T,ID extends Serializable>@Transactional public void deleteAllInBatch()
JpaRepositorydeleteAllInBatch in interface JpaRepository<T,ID extends Serializable>public T findOne(ID id)
findOne in interface CrudRepository<T,ID extends Serializable>protected Map<String,Object> getQueryHints()
Map with the query hints based on the current CrudMethodMetadata and potential
EntityGraph information.public T getOne(ID id)
JpaRepositorygetOne in interface JpaRepository<T,ID extends Serializable>id - must not be null.EntityManager.getReference(Class, Object)public boolean exists(ID id)
exists in interface CrudRepository<T,ID extends Serializable>public List<T> findAll()
findAll in interface JpaRepository<T,ID extends Serializable>findAll in interface CrudRepository<T,ID extends Serializable>public List<T> findAll(Iterable<ID> ids)
findAll in interface JpaRepository<T,ID extends Serializable>findAll in interface CrudRepository<T,ID extends Serializable>public List<T> findAll(Sort sort)
findAll in interface JpaRepository<T,ID extends Serializable>findAll in interface PagingAndSortingRepository<T,ID extends Serializable>public Page<T> findAll(Pageable pageable)
findAll in interface PagingAndSortingRepository<T,ID extends Serializable>public T findOne(Specification<T> spec)
JpaSpecificationExecutorSpecification.findOne in interface JpaSpecificationExecutor<T>public List<T> findAll(Specification<T> spec)
JpaSpecificationExecutorSpecification.findAll in interface JpaSpecificationExecutor<T>public Page<T> findAll(Specification<T> spec, Pageable pageable)
JpaSpecificationExecutorPage of entities matching the given Specification.findAll in interface JpaSpecificationExecutor<T>public List<T> findAll(Specification<T> spec, Sort sort)
JpaSpecificationExecutorSpecification and Sort.findAll in interface JpaSpecificationExecutor<T>public <S extends T> 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 extends Serializable>findAll in interface QueryByExampleExecutor<T>public <S extends T> List<S> findAll(Example<S> example, Sort sort)
findAll in interface JpaRepository<T,ID extends Serializable>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 extends Serializable>public long count(Specification<T> spec)
JpaSpecificationExecutorSpecification will return.count in interface JpaSpecificationExecutor<T>spec - the Specification to count instances for@Transactional public <S extends T> S save(S entity)
save in interface CrudRepository<T,ID extends Serializable>@Transactional public <S extends T> S saveAndFlush(S entity)
JpaRepositorysaveAndFlush in interface JpaRepository<T,ID extends Serializable>@Transactional public <S extends T> List<S> save(Iterable<S> entities)
save in interface JpaRepository<T,ID extends Serializable>save in interface CrudRepository<T,ID extends Serializable>@Transactional public void flush()
JpaRepositoryflush in interface JpaRepository<T,ID extends Serializable>@Deprecated protected Page<T> readPage(javax.persistence.TypedQuery<T> query, Pageable pageable, Specification<T> spec)
readPage(TypedQuery, Class, Pageable, Specification) insteadquery - must not be null.spec - can be null.pageable - can be null.protected <S extends T> Page<S> readPage(javax.persistence.TypedQuery<S> query, Class<S> domainClass, Pageable pageable, 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(Specification<T> spec, Pageable pageable)
TypedQuery from the given Specification.spec - can be null.pageable - can be null.protected <S extends T> javax.persistence.TypedQuery<S> getQuery(Specification<S> spec, Class<S> domainClass, Pageable pageable)
TypedQuery from the given Specification.spec - can be null.domainClass - must not be null.pageable - can be null.protected javax.persistence.TypedQuery<T> getQuery(Specification<T> spec, Sort sort)
spec - can be null.sort - can be null.protected <S extends T> javax.persistence.TypedQuery<S> getQuery(Specification<S> spec, Class<S> domainClass, Sort sort)
spec - can be null.domainClass - must not be null.sort - can be null.@Deprecated protected javax.persistence.TypedQuery<Long> getCountQuery(Specification<T> spec)
getCountQuery(Specification, Class) insteadSpecification.spec - can be null.protected <S extends T> javax.persistence.TypedQuery<Long> getCountQuery(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.