Class HibernateJpaOperations

java.lang.Object
io.micronaut.data.hibernate.operations.AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
io.micronaut.data.hibernate.operations.HibernateJpaOperations
All Implemented Interfaces:
io.micronaut.context.ApplicationContextProvider, io.micronaut.core.convert.ConversionServiceProvider, JpaRepositoryOperations, AsyncCapableRepository, HintsCapableRepository, PrimaryRepositoryOperations, ReactiveCapableRepository, RepositoryOperations, PreparedQueryDecorator, StoredQueryDecorator

@EachBean(javax.sql.DataSource.class) public class HibernateJpaOperations extends AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query> implements JpaRepositoryOperations, AsyncCapableRepository, ReactiveCapableRepository
Implementation of the JpaRepositoryOperations interface for Hibernate.
Since:
1.0
Author:
graemerocher
  • Constructor Details

    • HibernateJpaOperations

      public HibernateJpaOperations(@NonNull @Parameter org.hibernate.SessionFactory sessionFactory, @NonNull @Parameter TransactionOperations<Connection> transactionOperations, @Named("io") @Nullable ExecutorService executorService, RuntimeEntityRegistry runtimeEntityRegistry, DataConversionService dataConversionService)
      Default constructor.
      Parameters:
      sessionFactory - The session factory
      transactionOperations - The transaction operations
      executorService - The executor service for I/O tasks to use
      runtimeEntityRegistry - The runtime entity registry
      dataConversionService - The data conversion service
  • Method Details

    • getEntity

      public <T> RuntimePersistentEntity<T> getEntity(Class<T> type)
      Description copied from class: AbstractHibernateOperations
      Gets the persistence entity.
      Specified by:
      getEntity in interface RepositoryOperations
      Specified by:
      getEntity in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Type Parameters:
      T - The entity type
      Parameters:
      type - The entity type
      Returns:
      The persistent entity
    • getApplicationContext

      public io.micronaut.context.ApplicationContext getApplicationContext()
      Specified by:
      getApplicationContext in interface io.micronaut.context.ApplicationContextProvider
      Overrides:
      getApplicationContext in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Returns:
      The application context
    • getConversionService

      public io.micronaut.core.convert.ConversionService getConversionService()
      Specified by:
      getConversionService in interface io.micronaut.core.convert.ConversionServiceProvider
      Overrides:
      getConversionService in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Returns:
      The conversion service
    • setParameter

      protected void setParameter(jakarta.persistence.Query query, String parameterName, Object value)
      Description copied from class: AbstractHibernateOperations
      Sets a parameter into query.
      Specified by:
      setParameter in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Parameters:
      query - The query
      parameterName - The parameter name
      value - The value
    • setParameter

      protected void setParameter(jakarta.persistence.Query query, String parameterName, Object value, io.micronaut.core.type.Argument argument)
      Description copied from class: AbstractHibernateOperations
      Sets parameter into query.
      Specified by:
      setParameter in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Parameters:
      query - The query
      parameterName - The parameter name
      value - The value
      argument - The argument
    • setParameterList

      protected void setParameterList(jakarta.persistence.Query query, String parameterName, Collection<Object> value)
      Description copied from class: AbstractHibernateOperations
      Sets a list parameter into query.
      Specified by:
      setParameterList in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Parameters:
      query - The query
      parameterName - The parameter name
      value - The value
    • setParameterList

      protected void setParameterList(jakarta.persistence.Query query, String parameterName, Collection<Object> value, io.micronaut.core.type.Argument argument)
      Description copied from class: AbstractHibernateOperations
      Sets a list parameter into query.
      Specified by:
      setParameterList in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Parameters:
      query - The query
      parameterName - The parameter name
      value - The value
      argument - The argument
    • setHint

      protected void setHint(jakarta.persistence.Query query, String hintName, Object value)
      Description copied from class: AbstractHibernateOperations
      Sets a hint.
      Specified by:
      setHint in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Parameters:
      query - The query
      hintName - The hint name
      value - The value
    • getEntityGraph

      protected <T> org.hibernate.graph.RootGraph<T> getEntityGraph(org.hibernate.Session session, Class<T> entityType, String graphName)
      Description copied from class: AbstractHibernateOperations
      Gets an entity graph.
      Specified by:
      getEntityGraph in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Type Parameters:
      T - The entity type
      Parameters:
      session - The session
      entityType - The entity type
      graphName - The graph name
      Returns:
      The graph
    • createEntityGraph

      protected <T> org.hibernate.graph.RootGraph<T> createEntityGraph(org.hibernate.Session session, Class<T> entityType)
      Description copied from class: AbstractHibernateOperations
      Creates an entity graph.
      Specified by:
      createEntityGraph in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Type Parameters:
      T - The entityType
      Parameters:
      session - The session
      entityType - The entityType
      Returns:
      The graph
    • createQuery

      protected jakarta.persistence.Query createQuery(org.hibernate.Session session, String query, Class<?> resultType)
      Description copied from class: AbstractHibernateOperations
      Create a new query.
      Specified by:
      createQuery in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Parameters:
      session - The session
      query - The query
      resultType - The result type
      Returns:
      new query
    • createNativeQuery

      protected jakarta.persistence.Query createNativeQuery(org.hibernate.Session session, String query, Class<?> resultType)
      Description copied from class: AbstractHibernateOperations
      Create a new native query.
      Specified by:
      createNativeQuery in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Parameters:
      session - The session
      query - The query
      resultType - The result type
      Returns:
      new query
    • createQuery

      protected jakarta.persistence.Query createQuery(org.hibernate.Session session, jakarta.persistence.criteria.CriteriaQuery<?> criteriaQuery)
      Description copied from class: AbstractHibernateOperations
      Create a native query.
      Specified by:
      createQuery in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Parameters:
      session - The session
      criteriaQuery - The criteriaQuery
      Returns:
      new query
    • setOffset

      protected void setOffset(jakarta.persistence.Query query, int offset)
      Description copied from class: AbstractHibernateOperations
      Sets the offset value.
      Specified by:
      setOffset in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Parameters:
      query - The query
      offset - The offset value
    • setMaxResults

      protected void setMaxResults(jakarta.persistence.Query query, int max)
      Description copied from class: AbstractHibernateOperations
      Sets the max results value.
      Specified by:
      setMaxResults in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Parameters:
      query - The query
      max - The max value
    • getQueryHints

      @NonNull public Map<String,Object> getQueryHints(@NonNull StoredQuery<?,?> storedQuery)
      Description copied from interface: HintsCapableRepository
      Obtain any custom query hints for this method and repository implementation.
      Specified by:
      getQueryHints in interface HintsCapableRepository
      Overrides:
      getQueryHints in class AbstractHibernateOperations<org.hibernate.Session,jakarta.persistence.Query,jakarta.persistence.Query>
      Parameters:
      storedQuery - The stored query
      Returns:
      THe query hints
    • findOne

      @Nullable public <T> T findOne(@NonNull Class<T> type, @NonNull Serializable id)
      Description copied from interface: RepositoryOperations
      Find one by ID.
      Specified by:
      findOne in interface RepositoryOperations
      Type Parameters:
      T - The generic type
      Parameters:
      type - The type
      id - The id
      Returns:
      A result or null
    • load

      @NonNull public <T> T load(@NonNull Class<T> type, @NonNull Serializable id)
      Description copied from interface: JpaRepositoryOperations
      Create an uninitialized proxy.
      Specified by:
      load in interface JpaRepositoryOperations
      Type Parameters:
      T - the entity type
      Parameters:
      type - the entity type
      id - the entity id
      Returns:
      an uninitialized proxy
    • findOne

      @Nullable public <T, R> R findOne(@NonNull PreparedQuery<T,R> preparedQuery)
      Description copied from interface: RepositoryOperations
      Find one by Query.
      Specified by:
      findOne in interface RepositoryOperations
      Type Parameters:
      T - The generic resultType
      R - The result type
      Parameters:
      preparedQuery - The prepared query
      Returns:
      A result or null
    • exists

      public <T> boolean exists(@NonNull PreparedQuery<T,Boolean> preparedQuery)
      Description copied from interface: RepositoryOperations
      Execute a query that checks for existence.
      Specified by:
      exists in interface RepositoryOperations
      Type Parameters:
      T - The generic resultType
      Parameters:
      preparedQuery - The prepared query
      Returns:
      A result or null
    • findAll

      @NonNull public <T> Iterable<T> findAll(@NonNull PagedQuery<T> pagedQuery)
      Description copied from interface: RepositoryOperations
      Finds all results for the given query.
      Specified by:
      findAll in interface RepositoryOperations
      Type Parameters:
      T - The generic type
      Parameters:
      pagedQuery - The root entity
      Returns:
      An iterable result
    • findStream

      @NonNull public <T> Stream<T> findStream(@NonNull PagedQuery<T> pagedQuery)
      Description copied from interface: RepositoryOperations
      Finds a stream for the given arguments.
      Specified by:
      findStream in interface RepositoryOperations
      Type Parameters:
      T - The generic type
      Parameters:
      pagedQuery - The query
      Returns:
      The stream
    • findPage

      public <R> Page<R> findPage(@NonNull PagedQuery<R> pagedQuery)
      Description copied from interface: RepositoryOperations
      Find a page for the given entity and pageable.
      Specified by:
      findPage in interface RepositoryOperations
      Type Parameters:
      R - The entity generic type
      Parameters:
      pagedQuery - The query
      Returns:
      The page type
    • count

      public <T> long count(PagedQuery<T> pagedQuery)
      Description copied from interface: RepositoryOperations
      Counts all results for the given query.
      Specified by:
      count in interface RepositoryOperations
      Type Parameters:
      T - The generic type
      Parameters:
      pagedQuery - The paged query
      Returns:
      An iterable result
    • findAll

      @NonNull public <T, R> Iterable<R> findAll(@NonNull PreparedQuery<T,R> preparedQuery)
      Description copied from interface: RepositoryOperations
      Finds all results for the given query.
      Specified by:
      findAll in interface RepositoryOperations
      Type Parameters:
      T - The entity type
      R - The result type
      Parameters:
      preparedQuery - The prepared query
      Returns:
      An iterable result
    • persist

      public <T> T persist(@NonNull InsertOperation<T> operation)
      Description copied from interface: RepositoryOperations
      Persist the operation returning a possibly new entity.
      Specified by:
      persist in interface RepositoryOperations
      Type Parameters:
      T - The generic type
      Parameters:
      operation - The operation
      Returns:
      The operation
    • update

      @NonNull public <T> T update(@NonNull UpdateOperation<T> operation)
      Description copied from interface: RepositoryOperations
      Updates the entity for the given operation.
      Specified by:
      update in interface RepositoryOperations
      Type Parameters:
      T - The generic type
      Parameters:
      operation - The operation
      Returns:
      The operation
    • updateAll

      @NonNull public <T> Iterable<T> updateAll(@NonNull UpdateBatchOperation<T> operation)
      Description copied from interface: RepositoryOperations
      Updates the entities for the given operation.
      Specified by:
      updateAll in interface RepositoryOperations
      Type Parameters:
      T - The generic type
      Parameters:
      operation - The operation
      Returns:
      The updated entities
    • persistAll

      @NonNull public <T> Iterable<T> persistAll(@NonNull InsertBatchOperation<T> operation)
      Description copied from interface: RepositoryOperations
      Persist all the given entities.
      Specified by:
      persistAll in interface RepositoryOperations
      Type Parameters:
      T - The generic type
      Parameters:
      operation - The operation
      Returns:
      The entities, possibly mutated
    • executeUpdate

      @NonNull public Optional<Number> executeUpdate(@NonNull PreparedQuery<?,Number> preparedQuery)
      Description copied from interface: RepositoryOperations
      Executes an update for the given query and parameter values. If it is possible to return the number of objects updated, then do so.
      Specified by:
      executeUpdate in interface RepositoryOperations
      Parameters:
      preparedQuery - The prepared query
      Returns:
      An optional number with the count of the number of records updated
    • delete

      public <T> int delete(@NonNull DeleteOperation<T> operation)
      Description copied from interface: RepositoryOperations
      Deletes the entity.
      Specified by:
      delete in interface RepositoryOperations
      Type Parameters:
      T - The generic type
      Parameters:
      operation - The operation
      Returns:
      The number of entities deleted
    • deleteAll

      public <T> Optional<Number> deleteAll(@NonNull DeleteBatchOperation<T> operation)
      Description copied from interface: RepositoryOperations
      Deletes all the entities of the given type.
      Specified by:
      deleteAll in interface RepositoryOperations
      Type Parameters:
      T - The generic type
      Parameters:
      operation - The operation
      Returns:
      The number of entities deleted
    • findStream

      @NonNull public <T, R> Stream<R> findStream(@NonNull PreparedQuery<T,R> preparedQuery)
      Description copied from interface: RepositoryOperations
      Finds all results for the given query.
      Specified by:
      findStream in interface RepositoryOperations
      Type Parameters:
      T - The entity type
      R - The result type
      Parameters:
      preparedQuery - The prepared query
      Returns:
      An iterable result
    • async

      @NonNull public ExecutorAsyncOperations async()
      Specified by:
      async in interface AsyncCapableRepository
      Returns:
      The async operations.
    • reactive

      @NonNull public ReactiveRepositoryOperations reactive()
      Specified by:
      reactive in interface ReactiveCapableRepository
      Returns:
      The reactive operations instance.
    • getCurrentEntityManager

      @NonNull public jakarta.persistence.EntityManager getCurrentEntityManager()
      Specified by:
      getCurrentEntityManager in interface JpaRepositoryOperations
      Returns:
      The currrent entity manager
    • getEntityManagerFactory

      @NonNull public jakarta.persistence.EntityManagerFactory getEntityManagerFactory()
      Specified by:
      getEntityManagerFactory in interface JpaRepositoryOperations
      Returns:
      The entity manager factory
    • flush

      public void flush()
      Description copied from interface: JpaRepositoryOperations
      Flush the current session.
      Specified by:
      flush in interface JpaRepositoryOperations