Interface BaseJpaRepository<T,ID>

All Superinterfaces:
org.springframework.data.repository.query.QueryByExampleExecutor<T>, org.springframework.data.repository.Repository<T,ID>
All Known Implementing Classes:
BaseJpaRepositoryImpl

@NoRepositoryBean public interface BaseJpaRepository<T,ID> extends org.springframework.data.repository.Repository<T,ID>, org.springframework.data.repository.query.QueryByExampleExecutor<T>
The BaseJpaRepository fixes many of the problems that the default Spring Data JpaRepository suffers from.

For more details about how to use it, check out this article on vladmihalcea.com.

Version:
2.21.0
Author:
Vlad Mihalcea
  • Method Summary

    Modifier and Type
    Method
    Description
    long
     
    void
    delete(T entity)
     
    void
     
    void
     
    void
     
    boolean
     
     
     
    void
     
     
    lockById(ID id, jakarta.persistence.LockModeType lockMode)
    Lock the entity with the provided identifier.
    <S extends T>
    S
    merge(S entity)
    The persist method allows you to pass the provided entity to the merge method of the underlying JPA EntityManager.
    <S extends T>
    List<S>
    mergeAll(Iterable<S> entities)
    The mergeAll method allows you to pass the provided entities to the merge method of the underlying JPA EntityManager.
    <S extends T>
    List<S>
    The mergeAllAndFlush method allows you to pass the provided entities to the merge method of the underlying JPA EntityManager and call flush afterwards.
    <S extends T>
    S
    mergeAndFlush(S entity)
    The mergeAndFlush method allows you to pass the provided entity to the merge method of the underlying JPA EntityManager and call flush afterwards.
    <S extends T>
    S
    persist(S entity)
    The persist method allows you to pass the provided entity to the persist method of the underlying JPA EntityManager.
    <S extends T>
    List<S>
    persistAll(Iterable<S> entities)
    The persistAll method allows you to pass the provided entities to the persist method of the underlying JPA EntityManager.
    <S extends T>
    List<S>
    The persistAll method allows you to pass the provided entities to the persist method of the underlying JPA EntityManager and call flush afterwards.
    <S extends T>
    S
    persistAndFlush(S entity)
    The persistAndFlush method allows you to pass the provided entity to the persist method of the underlying JPA EntityManager and call flush afterwards.
    <S extends T>
    S
    update(S entity)
    The update method allows you to pass the provided entity to the update method of the underlying JPA EntityManager.
    <S extends T>
    List<S>
    updateAll(Iterable<S> entities)
    The updateAll method allows you to pass the provided entities to the update method of the underlying JPA EntityManager.
    <S extends T>
    List<S>
    The updateAllAndFlush method allows you to pass the provided entities to the update method of the underlying JPA EntityManager and call flush afterwards.
    <S extends T>
    S
    updateAndFlush(S entity)
    The updateAndFlush method allows you to pass the provided entity to the update method of the underlying JPA EntityManager and call flush afterwards.

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

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

    • findById

      Optional<T> findById(ID id)
    • existsById

      boolean existsById(ID id)
    • getReferenceById

      T getReferenceById(ID id)
    • findAllById

      List<T> findAllById(Iterable<ID> ids)
    • count

      long count()
    • delete

      void delete(T entity)
    • deleteAllInBatch

      void deleteAllInBatch(Iterable<T> entities)
    • deleteById

      void deleteById(ID id)
    • deleteAllByIdInBatch

      void deleteAllByIdInBatch(Iterable<ID> ids)
    • flush

      void flush()
    • persist

      <S extends T> S persist(S entity)
      The persist method allows you to pass the provided entity to the persist method of the underlying JPA EntityManager.
      Type Parameters:
      S - entity type
      Parameters:
      entity - entity to persist
      Returns:
      entity
    • persistAndFlush

      <S extends T> S persistAndFlush(S entity)
      The persistAndFlush method allows you to pass the provided entity to the persist method of the underlying JPA EntityManager and call flush afterwards.
      Type Parameters:
      S - entity type
      Parameters:
      entity - entity to persist
      Returns:
      entity
    • persistAll

      <S extends T> List<S> persistAll(Iterable<S> entities)
      The persistAll method allows you to pass the provided entities to the persist method of the underlying JPA EntityManager.
      Type Parameters:
      S - entity type
      Parameters:
      entities - entities to persist
      Returns:
      entities
    • persistAllAndFlush

      <S extends T> List<S> persistAllAndFlush(Iterable<S> entities)
      The persistAll method allows you to pass the provided entities to the persist method of the underlying JPA EntityManager and call flush afterwards.
      Type Parameters:
      S - entity type
      Parameters:
      entities - entities to persist
      Returns:
      entities
    • merge

      <S extends T> S merge(S entity)
      The persist method allows you to pass the provided entity to the merge method of the underlying JPA EntityManager.
      Type Parameters:
      S - entity type
      Parameters:
      entity - entity to merge
      Returns:
      entity
    • mergeAndFlush

      <S extends T> S mergeAndFlush(S entity)
      The mergeAndFlush method allows you to pass the provided entity to the merge method of the underlying JPA EntityManager and call flush afterwards.
      Type Parameters:
      S - entity type
      Parameters:
      entity - entity to merge
      Returns:
      entity
    • mergeAll

      <S extends T> List<S> mergeAll(Iterable<S> entities)
      The mergeAll method allows you to pass the provided entities to the merge method of the underlying JPA EntityManager.
      Type Parameters:
      S - entity type
      Parameters:
      entities - entities to merge
      Returns:
      entities
    • mergeAllAndFlush

      <S extends T> List<S> mergeAllAndFlush(Iterable<S> entities)
      The mergeAllAndFlush method allows you to pass the provided entities to the merge method of the underlying JPA EntityManager and call flush afterwards.
      Type Parameters:
      S - entity type
      Parameters:
      entities - entities to persist
      Returns:
      entities
    • update

      <S extends T> S update(S entity)
      The update method allows you to pass the provided entity to the update method of the underlying JPA EntityManager.
      Type Parameters:
      S - entity type
      Parameters:
      entity - entity to update
      Returns:
      entity
    • updateAndFlush

      <S extends T> S updateAndFlush(S entity)
      The updateAndFlush method allows you to pass the provided entity to the update method of the underlying JPA EntityManager and call flush afterwards.
      Type Parameters:
      S - entity type
      Parameters:
      entity - entity to update
      Returns:
      entity
    • updateAll

      <S extends T> List<S> updateAll(Iterable<S> entities)
      The updateAll method allows you to pass the provided entities to the update method of the underlying JPA EntityManager.
      Type Parameters:
      S - entity type
      Parameters:
      entities - entities to update
      Returns:
      entities
    • updateAllAndFlush

      <S extends T> List<S> updateAllAndFlush(Iterable<S> entities)
      The updateAllAndFlush method allows you to pass the provided entities to the update method of the underlying JPA EntityManager and call flush afterwards.
      Type Parameters:
      S - entity type
      Parameters:
      entities - entities to update
      Returns:
      entities
    • lockById

      T lockById(ID id, jakarta.persistence.LockModeType lockMode)
      Lock the entity with the provided identifier.
      Parameters:
      id - entity identifier
      lockMode - entity lock mode
      Returns:
      entity