Package com.axelor.db

Class JpaSupport

java.lang.Object
com.axelor.db.JpaSupport
Direct Known Subclasses:
MailController, ResponseInterceptor, TaskController

public abstract class JpaSupport extends Object
This class provides some useful methods in JPA context, can be used as a base class for services to make it more convenient.
  • Constructor Details

    • JpaSupport

      public JpaSupport()
  • Method Details

    • getEntityManager

      protected jakarta.persistence.EntityManager getEntityManager()
      Get the instance of current EntityManager.
      Returns:
      the EntityManager instance
    • all

      protected <T extends Model> Query<T> all(Class<T> modelClass)
      Get the Query instance for the given model class.
      Type Parameters:
      T - the type of the model
      Parameters:
      modelClass - the model class
      Returns:
      an instance of Query
    • inTransaction

      protected void inTransaction(Runnable task)
      Run the given task inside a transaction that is committed after the task is completed.
      Parameters:
      task - the task to run
    • jdbcTask

      protected void jdbcTask(JpaSupport.JDBCTask task)
      Perform JDBC related task using the Connection managed by the current EntityManager.
      Parameters:
      task - The task to be performed
      Throws:
      jakarta.persistence.PersistenceException - Generally indicates wrapped SQLException