Class HibernateJpaOperations
java.lang.Object
io.micronaut.data.hibernate.operations.AbstractHibernateOperations<org.hibernate.Session,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>
implements JpaRepositoryOperations, AsyncCapableRepository, ReactiveCapableRepository
Implementation of the
JpaRepositoryOperations
interface for Hibernate.- Since:
- 1.0
- Author:
- graemerocher
-
Nested Class Summary
Nested classes/interfaces inherited from class io.micronaut.data.hibernate.operations.AbstractHibernateOperations
AbstractHibernateOperations.ResultCollector<R>
-
Field Summary
Fields inherited from class io.micronaut.data.hibernate.operations.AbstractHibernateOperations
dataConversionService, runtimeEntityRegistry
-
Constructor Summary
ConstructorsConstructorDescriptionHibernateJpaOperations
(org.hibernate.SessionFactory sessionFactory, TransactionOperations<Connection> transactionOperations, ExecutorService executorService, RuntimeEntityRegistry runtimeEntityRegistry, DataConversionService dataConversionService) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionasync()
<T> long
count
(PagedQuery<T> pagedQuery) Counts all results for the given query.protected <T> org.hibernate.graph.RootGraph<T>
createEntityGraph
(org.hibernate.Session session, Class<T> entityType) Creates an entity graph.protected jakarta.persistence.Query
createNativeQuery
(org.hibernate.Session session, String query, Class<?> resultType) Create a new native query.protected jakarta.persistence.Query
createQuery
(org.hibernate.Session session, jakarta.persistence.criteria.CriteriaQuery<?> criteriaQuery) Create a native query.protected jakarta.persistence.Query
createQuery
(org.hibernate.Session session, String query, Class<?> resultType) Create a new query.<T> int
delete
(DeleteOperation<T> operation) Deletes the entity.deleteAll
(DeleteBatchOperation<T> operation) Deletes all the entities of the given type.executeUpdate
(PreparedQuery<?, Number> preparedQuery) Executes an update for the given query and parameter values.<T> boolean
exists
(PreparedQuery<T, Boolean> preparedQuery) Execute a query that checks for existence.<T> Iterable<T>
findAll
(PagedQuery<T> pagedQuery) Finds all results for the given query.<T,
R> Iterable<R> findAll
(PreparedQuery<T, R> preparedQuery) Finds all results for the given query.<T,
R> R findOne
(PreparedQuery<T, R> preparedQuery) Find one by Query.<T> T
findOne
(Class<T> type, Serializable id) Find one by ID.<R> Page<R>
findPage
(PagedQuery<R> pagedQuery) Find a page for the given entity and pageable.<T> Stream<T>
findStream
(PagedQuery<T> pagedQuery) Finds a stream for the given arguments.<T,
R> Stream<R> findStream
(PreparedQuery<T, R> preparedQuery) Finds all results for the given query.void
flush()
Flush the current session.io.micronaut.context.ApplicationContext
io.micronaut.core.convert.ConversionService
jakarta.persistence.EntityManager
<T> RuntimePersistentEntity<T>
Gets the persistence entity.protected <T> org.hibernate.graph.RootGraph<T>
getEntityGraph
(org.hibernate.Session session, Class<T> entityType, String graphName) Gets an entity graph.jakarta.persistence.EntityManagerFactory
getQueryHints
(StoredQuery<?, ?> storedQuery) Obtain any custom query hints for this method and repository implementation.<T> T
load
(Class<T> type, Serializable id) Create an uninitialized proxy.<T> T
persist
(InsertOperation<T> operation) Persist the operation returning a possibly new entity.<T> Iterable<T>
persistAll
(InsertBatchOperation<T> operation) Persist all the given entities.reactive()
protected void
Sets a hint.protected void
setMaxResults
(jakarta.persistence.Query query, int max) Sets the max results value.protected void
setOffset
(jakarta.persistence.Query query, int offset) Sets the offset value.protected void
setParameter
(jakarta.persistence.Query query, String parameterName, Object value) Sets a parameter into query.protected void
setParameter
(jakarta.persistence.Query query, String parameterName, Object value, io.micronaut.core.type.Argument argument) Sets parameter into query.protected void
setParameterList
(jakarta.persistence.Query query, String parameterName, Collection<Object> value) Sets a list parameter into query.protected void
setParameterList
(jakarta.persistence.Query query, String parameterName, Collection<Object> value, io.micronaut.core.type.Argument argument) Sets a list parameter into query.<T> T
update
(UpdateOperation<T> operation) Updates the entity for the given operation.<T> Iterable<T>
updateAll
(UpdateBatchOperation<T> operation) Updates the entities for the given operation.Methods inherited from class io.micronaut.data.hibernate.operations.AbstractHibernateOperations
bindParameters, collectCountOf, collectFindAll, collectFindOne, collectPagedResults, decorate, decorate, getFlushModeType, getParameterValue
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.data.operations.RepositoryOperations
executeDelete
-
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 factorytransactionOperations
- The transaction operationsexecutorService
- The executor service for I/O tasks to useruntimeEntityRegistry
- The runtime entity registrydataConversionService
- The data conversion service
-
-
Method Details
-
getEntity
Description copied from class:AbstractHibernateOperations
Gets the persistence entity.- Specified by:
getEntity
in interfaceRepositoryOperations
- Specified by:
getEntity
in classAbstractHibernateOperations<org.hibernate.Session,
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 interfaceio.micronaut.context.ApplicationContextProvider
- Overrides:
getApplicationContext
in classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Returns:
- The application context
-
getConversionService
public io.micronaut.core.convert.ConversionService getConversionService()- Specified by:
getConversionService
in interfaceio.micronaut.core.convert.ConversionServiceProvider
- Overrides:
getConversionService
in classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Returns:
- The conversion service
-
setParameter
Description copied from class:AbstractHibernateOperations
Sets a parameter into query.- Specified by:
setParameter
in classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Parameters:
query
- The queryparameterName
- The parameter namevalue
- 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 classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Parameters:
query
- The queryparameterName
- The parameter namevalue
- The valueargument
- 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 classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Parameters:
query
- The queryparameterName
- The parameter namevalue
- 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 classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Parameters:
query
- The queryparameterName
- The parameter namevalue
- The valueargument
- The argument
-
setHint
Description copied from class:AbstractHibernateOperations
Sets a hint.- Specified by:
setHint
in classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Parameters:
query
- The queryhintName
- The hint namevalue
- 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 classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Type Parameters:
T
- The entity type- Parameters:
session
- The sessionentityType
- The entity typegraphName
- 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 classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Type Parameters:
T
- The entityType- Parameters:
session
- The sessionentityType
- 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 classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Parameters:
session
- The sessionquery
- The queryresultType
- 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 classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Parameters:
session
- The sessionquery
- The queryresultType
- 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 classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Parameters:
session
- The sessioncriteriaQuery
- 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 classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Parameters:
query
- The queryoffset
- 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 classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Parameters:
query
- The querymax
- The max value
-
getQueryHints
Description copied from interface:HintsCapableRepository
Obtain any custom query hints for this method and repository implementation.- Specified by:
getQueryHints
in interfaceHintsCapableRepository
- Overrides:
getQueryHints
in classAbstractHibernateOperations<org.hibernate.Session,
jakarta.persistence.Query> - Parameters:
storedQuery
- The stored query- Returns:
- THe query hints
-
findOne
Description copied from interface:RepositoryOperations
Find one by ID.- Specified by:
findOne
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
type
- The typeid
- The id- Returns:
- A result or null
-
load
Description copied from interface:JpaRepositoryOperations
Create an uninitialized proxy.- Specified by:
load
in interfaceJpaRepositoryOperations
- Type Parameters:
T
- the entity type- Parameters:
type
- the entity typeid
- the entity id- Returns:
- an uninitialized proxy
-
findOne
Description copied from interface:RepositoryOperations
Find one by Query.- Specified by:
findOne
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic resultTypeR
- The result type- Parameters:
preparedQuery
- The prepared query- Returns:
- A result or null
-
exists
Description copied from interface:RepositoryOperations
Execute a query that checks for existence.- Specified by:
exists
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic resultType- Parameters:
preparedQuery
- The prepared query- Returns:
- A result or null
-
findAll
Description copied from interface:RepositoryOperations
Finds all results for the given query.- Specified by:
findAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
pagedQuery
- The root entity- Returns:
- An iterable result
-
findStream
Description copied from interface:RepositoryOperations
Finds a stream for the given arguments.- Specified by:
findStream
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
pagedQuery
- The query- Returns:
- The stream
-
findPage
Description copied from interface:RepositoryOperations
Find a page for the given entity and pageable.- Specified by:
findPage
in interfaceRepositoryOperations
- Type Parameters:
R
- The entity generic type- Parameters:
pagedQuery
- The query- Returns:
- The page type
-
count
Description copied from interface:RepositoryOperations
Counts all results for the given query.- Specified by:
count
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
pagedQuery
- The paged query- Returns:
- An iterable result
-
findAll
Description copied from interface:RepositoryOperations
Finds all results for the given query.- Specified by:
findAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The entity typeR
- The result type- Parameters:
preparedQuery
- The prepared query- Returns:
- An iterable result
-
persist
Description copied from interface:RepositoryOperations
Persist the operation returning a possibly new entity.- Specified by:
persist
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The operation
-
update
Description copied from interface:RepositoryOperations
Updates the entity for the given operation.- Specified by:
update
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The operation
-
updateAll
Description copied from interface:RepositoryOperations
Updates the entities for the given operation.- Specified by:
updateAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The updated entities
-
persistAll
Description copied from interface:RepositoryOperations
Persist all the given entities.- Specified by:
persistAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The entities, possibly mutated
-
executeUpdate
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 interfaceRepositoryOperations
- Parameters:
preparedQuery
- The prepared query- Returns:
- An optional number with the count of the number of records updated
-
delete
Description copied from interface:RepositoryOperations
Deletes the entity.- Specified by:
delete
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The number of entities deleted
-
deleteAll
Description copied from interface:RepositoryOperations
Deletes all the entities of the given type.- Specified by:
deleteAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The number of entities deleted
-
findStream
Description copied from interface:RepositoryOperations
Finds all results for the given query.- Specified by:
findStream
in interfaceRepositoryOperations
- Type Parameters:
T
- The entity typeR
- The result type- Parameters:
preparedQuery
- The prepared query- Returns:
- An iterable result
-
async
- Specified by:
async
in interfaceAsyncCapableRepository
- Returns:
- The async operations.
-
reactive
- Specified by:
reactive
in interfaceReactiveCapableRepository
- Returns:
- The reactive operations instance.
-
getCurrentEntityManager
@NonNull public jakarta.persistence.EntityManager getCurrentEntityManager()- Specified by:
getCurrentEntityManager
in interfaceJpaRepositoryOperations
- Returns:
- The currrent entity manager
-
getEntityManagerFactory
@NonNull public jakarta.persistence.EntityManagerFactory getEntityManagerFactory()- Specified by:
getEntityManagerFactory
in interfaceJpaRepositoryOperations
- Returns:
- The entity manager factory
-
flush
public void flush()Description copied from interface:JpaRepositoryOperations
Flush the current session.- Specified by:
flush
in interfaceJpaRepositoryOperations
-