public class HibernateUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_ENTITY_MANAGER_NAME |
Constructor and Description |
---|
HibernateUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
deproxy(T t)
Ensure a domain object is an actual persisted object and not a Hibernate proxy object by getting its real implementation.
|
static <T> T |
executeWithoutCache(GenericOperation<T> operation)
Attempts to execute the operation without L2 or query cache engaged.
|
static <T> T |
executeWithoutCache(GenericOperation<T> operation,
javax.persistence.EntityManager em)
During bulk operations such as reindexing we don't always want things to be cached.
|
static <T> T |
executeWithoutCache(GenericOperation<T> operation,
String persistenceUnitName)
Attempts to execute the operation without L2 or query cache engaged.
|
static javax.persistence.EntityManager |
getCurrentDefaultEntityManager()
Retrieves the current, default
EntityManager , with the PersistenceUnit name "blPU", or null if it has not been initialized and bound to the Thread. |
static javax.persistence.EntityManager |
getCurrentEntityManager(String persistenceUnitName)
Retrieves the current, default
EntityManager , with the PersistenceUnit name provided, or null if it has not been initialized and bound to the Thread. |
public static final String DEFAULT_ENTITY_MANAGER_NAME
public static <T> T deproxy(T t)
Ensure a domain object is an actual persisted object and not a Hibernate proxy object by getting its real implementation.
This is primarily useful when retrieving a lazy loaded object that has been subclassed and you have the intention of casting it.
t
- the domain object to deproxypublic static <T> T executeWithoutCache(GenericOperation<T> operation, javax.persistence.EntityManager em) throws Exception
EntityManager
is null, the operation is executed without affecting the cache settings.operation
- em
- G
Exception
public static <T> T executeWithoutCache(GenericOperation<T> operation, String persistenceUnitName) throws Exception
PersistenceUnit
with the provided name.
If no EntityManager
is bound to the thread for the provided PersistenceUnit
,
then the operation is performed without modifying the cache mode. Note that this does not create an EntityManager
if one is not already initialized.operation
- persistenceUnitName
- Exception
public static <T> T executeWithoutCache(GenericOperation<T> operation) throws Exception
PersistenceUnit
name "blPU". If no EntityManager
is bound to the thread,
then the operation is performed without modifying the cache mode. Note that this does not create an EntityManager
if one is not already initialized.operation
- Exception
public static javax.persistence.EntityManager getCurrentEntityManager(String persistenceUnitName)
EntityManager
, with the PersistenceUnit
name provided, or null if it has not been initialized and bound to the Thread.persistenceUnitName
- public static javax.persistence.EntityManager getCurrentDefaultEntityManager()
EntityManager
, with the PersistenceUnit
name "blPU", or null if it has not been initialized and bound to the Thread.Copyright © 2022. All rights reserved.