Interface EntityManagerStore

All Known Implementing Classes:
EntityManagerStoreImpl

public interface EntityManagerStore
Author:
Sebastian Hennebrueder
  • Method Summary

    Modifier and Type
    Method
    Description
    jakarta.persistence.EntityManager
    Creates an entity manager and stores it in a stack.
    jakarta.persistence.EntityManager
    get()
    Looks for the current entity manager and returns it.
    void
    unregister(jakarta.persistence.EntityManager entityManager)
    Removes an entity manager from the thread local stack.
  • Method Details

    • get

      jakarta.persistence.EntityManager get()
      Looks for the current entity manager and returns it. If no entity manager was found, this method logs a warn message and returns null. This will cause a NullPointerException in most cases and will cause a stack trace starting from your service method.
      Returns:
      the currently used entity manager or null if none was found
    • createAndRegister

      jakarta.persistence.EntityManager createAndRegister()
      Creates an entity manager and stores it in a stack. The use of a stack allows to implement transaction with a 'requires new' behaviour.
      Returns:
      the created entity manager
    • unregister

      void unregister(jakarta.persistence.EntityManager entityManager)
      Removes an entity manager from the thread local stack. It needs to be created using the createAndRegister() method.
      Parameters:
      entityManager - - the entity manager to remove
      Throws:
      IllegalStateException - in case the entity manager was not found on the stack