Class HibernateRepositoryImpl<T>

java.lang.Object
io.hypersistence.utils.spring.repository.HibernateRepositoryImpl<T>
All Implemented Interfaces:
HibernateRepository<T>

public class HibernateRepositoryImpl<T> extends Object implements HibernateRepository<T>
Author:
Vlad Mihalcea
  • Constructor Summary

    Constructors
    Constructor
    Description
    HibernateRepositoryImpl(jakarta.persistence.EntityManager entityManager)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected <R> R
    executeBatch(Supplier<R> callback)
     
    The findAll method is a terrible Anti-Pattern.
    protected Integer
    getBatchSize(org.hibernate.Session session)
     
    <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
    save(S entity)
    The save method should be avoided.
    <S extends T>
    List<S>
    saveAll(Iterable<S> entities)
    The save method should be avoided.
    <S extends T>
    List<S>
    The saveAllAndFlush method should be avoided.
    <S extends T>
    S
    saveAndFlush(S entity)
    The saveAndFlush method should be avoided.
    protected org.hibernate.Session
     
    protected <S extends T>
    S
     
    <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 class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HibernateRepositoryImpl

      public HibernateRepositoryImpl(jakarta.persistence.EntityManager entityManager)
  • Method Details

    • findAll

      public List<T> findAll()
      Description copied from interface: HibernateRepository
      The findAll method is a terrible Anti-Pattern.

      For more details about why you should not use the findAll method by default, check out this article.

      Specified by:
      findAll in interface HibernateRepository<T>
      Returns:
      all the records from the database table this entity is mapped to
    • save

      public <S extends T> S save(S entity)
      Description copied from interface: HibernateRepository
      The save method should be avoided.

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

      Specified by:
      save in interface HibernateRepository<T>
    • saveAll

      public <S extends T> List<S> saveAll(Iterable<S> entities)
      Description copied from interface: HibernateRepository
      The save method should be avoided.

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

      Specified by:
      saveAll in interface HibernateRepository<T>
    • saveAndFlush

      public <S extends T> S saveAndFlush(S entity)
      Description copied from interface: HibernateRepository
      The saveAndFlush method should be avoided.

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

      Specified by:
      saveAndFlush in interface HibernateRepository<T>
    • saveAllAndFlush

      public <S extends T> List<S> saveAllAndFlush(Iterable<S> entities)
      Description copied from interface: HibernateRepository
      The saveAllAndFlush method should be avoided.

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

      Specified by:
      saveAllAndFlush in interface HibernateRepository<T>
    • persist

      public <S extends T> S persist(S entity)
      Description copied from interface: HibernateRepository
      The persist method allows you to pass the provided entity to the persist method of the underlying JPA EntityManager.
      Specified by:
      persist in interface HibernateRepository<T>
      Type Parameters:
      S - entity type
      Parameters:
      entity - entity to persist
      Returns:
      entity
    • persistAndFlush

      public <S extends T> S persistAndFlush(S entity)
      Description copied from interface: HibernateRepository
      The persistAndFlush method allows you to pass the provided entity to the persist method of the underlying JPA EntityManager and call flush afterwards.
      Specified by:
      persistAndFlush in interface HibernateRepository<T>
      Type Parameters:
      S - entity type
      Parameters:
      entity - entity to persist
      Returns:
      entity
    • persistAll

      public <S extends T> List<S> persistAll(Iterable<S> entities)
      Description copied from interface: HibernateRepository
      The persistAll method allows you to pass the provided entities to the persist method of the underlying JPA EntityManager.
      Specified by:
      persistAll in interface HibernateRepository<T>
      Type Parameters:
      S - entity type
      Parameters:
      entities - entities to persist
      Returns:
      entities
    • persistAllAndFlush

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

      public <S extends T> S merge(S entity)
      Description copied from interface: HibernateRepository
      The persist method allows you to pass the provided entity to the merge method of the underlying JPA EntityManager.
      Specified by:
      merge in interface HibernateRepository<T>
      Type Parameters:
      S - entity type
      Parameters:
      entity - entity to merge
      Returns:
      entity
    • mergeAndFlush

      public <S extends T> S mergeAndFlush(S entity)
      Description copied from interface: HibernateRepository
      The mergeAndFlush method allows you to pass the provided entity to the merge method of the underlying JPA EntityManager and call flush afterwards.
      Specified by:
      mergeAndFlush in interface HibernateRepository<T>
      Type Parameters:
      S - entity type
      Parameters:
      entity - entity to merge
      Returns:
      entity
    • mergeAll

      public <S extends T> List<S> mergeAll(Iterable<S> entities)
      Description copied from interface: HibernateRepository
      The mergeAll method allows you to pass the provided entities to the merge method of the underlying JPA EntityManager.
      Specified by:
      mergeAll in interface HibernateRepository<T>
      Type Parameters:
      S - entity type
      Parameters:
      entities - entities to merge
      Returns:
      entities
    • mergeAllAndFlush

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

      public <S extends T> S update(S entity)
      Description copied from interface: HibernateRepository
      The update method allows you to pass the provided entity to the update method of the underlying JPA EntityManager.
      Specified by:
      update in interface HibernateRepository<T>
      Type Parameters:
      S - entity type
      Parameters:
      entity - entity to update
      Returns:
      entity
    • updateAndFlush

      public <S extends T> S updateAndFlush(S entity)
      Description copied from interface: HibernateRepository
      The updateAndFlush method allows you to pass the provided entity to the update method of the underlying JPA EntityManager and call flush afterwards.
      Specified by:
      updateAndFlush in interface HibernateRepository<T>
      Type Parameters:
      S - entity type
      Parameters:
      entity - entity to update
      Returns:
      entity
    • updateAll

      public <S extends T> List<S> updateAll(Iterable<S> entities)
      Description copied from interface: HibernateRepository
      The updateAll method allows you to pass the provided entities to the update method of the underlying JPA EntityManager.
      Specified by:
      updateAll in interface HibernateRepository<T>
      Type Parameters:
      S - entity type
      Parameters:
      entities - entities to update
      Returns:
      entities
    • updateAllAndFlush

      public <S extends T> List<S> updateAllAndFlush(Iterable<S> entities)
      Description copied from interface: HibernateRepository
      The updateAllAndFlush method allows you to pass the provided entities to the update method of the underlying JPA EntityManager and call flush afterwards.
      Specified by:
      updateAllAndFlush in interface HibernateRepository<T>
      Type Parameters:
      S - entity type
      Parameters:
      entities - entities to update
      Returns:
      entities
    • getBatchSize

      protected Integer getBatchSize(org.hibernate.Session session)
    • executeBatch

      protected <R> R executeBatch(Supplier<R> callback)
    • session

      protected org.hibernate.Session session()
    • unsupportedSave

      protected <S extends T> S unsupportedSave()