public class HibernateModule extends OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader> implements Module, Flushable
SessionFactory is created when requested and injected into all fields or methods of the test
annotated with HibernateSessionFactory.
It is highly recommended to write a unit test that invokes HibernateUnitils.assertMappingWithDatabaseConsistent(),
This is a very useful test that verifies whether the mapping of all your Hibernate mapped objects still corresponds
with the actual structure of the database.| Modifier and Type | Class and Description |
|---|---|
protected class |
HibernateModule.HibernateTestListener
The
TestListener for this module |
OrmModule.OrmTestListener| Modifier and Type | Field and Description |
|---|---|
static String |
PROPKEY_CONFIGURATION_CLASS_NAME |
configuredOrmPersistenceUnitCache, databaseName, ormPersistenceUnitLoader, ormSpringSupport, persistenceUnitConfigLoader, wrappers| Constructor and Description |
|---|
HibernateModule() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterInit() |
void |
assertMappingWithDatabaseConsistent(Object testObject)
Checks if the mapping of the Hibernate managed objects with the database is correct.
|
protected HibernateAnnotationConfigLoader |
createOrmConfigLoader() |
protected OrmPersistenceUnitLoader<org.hibernate.SessionFactory,org.hibernate.cfg.Configuration,OrmConfig> |
createOrmPersistenceUnitLoader() |
protected org.hibernate.Session |
doGetActivePersistenceContext(Object testObject)
Implementations of this method must return the persistence context object that is associated with the current
transaction, if any.
|
protected org.hibernate.Session |
doGetPersistenceContext(Object testObject)
Implementations of this method must return a persistence context object, and must be associated with the
current transaction active in unitils.
|
protected void |
flushOrmPersistenceContext(org.hibernate.Session activeSession)
Flushes all pending update, using the given active persistence context
|
Class<? extends org.hibernate.cfg.Configuration> |
getConfigurationObjectClass() |
protected org.hibernate.dialect.Dialect |
getDatabaseDialect(org.hibernate.cfg.Configuration configuration)
Gets the database dialect from the given Hibernate Configuration
|
protected void |
getDatabaseName(Object testObject,
Method testMethod) |
protected DataSource |
getDataSource() |
protected String |
getOrmSpringSupportImplClassName() |
protected Class<org.hibernate.SessionFactory> |
getPersistenceUnitClass() |
protected Class<HibernateSessionFactory> |
getPersistenceUnitConfigAnnotationClass() |
TestListener |
getTestListener() |
void |
init(Properties configuration) |
void |
registerTransactionManagementConfiguration() |
flushDatabaseUpdates, getActivePersistenceContext, getConfigurationObject, getConfiguredPersistenceUnit, getDatabaseModule, getPersistenceContext, getPersistenceUnit, getPersistenceUnitConfig, initOrmSpringSupport, injectOrmPersistenceUnitIntoTestObject, isPersistenceUnitConfiguredFor, isSpringModuleEnabledclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitflushDatabaseUpdatespublic static final String PROPKEY_CONFIGURATION_CLASS_NAME
public void init(Properties configuration)
init in interface Moduleinit in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>configuration - The Unitils configuration, not nullpublic void afterInit()
afterInit in interface ModuleafterInit in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>public void registerTransactionManagementConfiguration()
protected HibernateAnnotationConfigLoader createOrmConfigLoader()
createOrmConfigLoader in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>ResourceConfigLoader that scans a test object for a persistence
unit configuration, and returns a specific subtype of OrmConfig that wraps this configurationprotected Class<HibernateSessionFactory> getPersistenceUnitConfigAnnotationClass()
getPersistenceUnitConfigAnnotationClass in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>protected Class<org.hibernate.SessionFactory> getPersistenceUnitClass()
getPersistenceUnitClass in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>protected OrmPersistenceUnitLoader<org.hibernate.SessionFactory,org.hibernate.cfg.Configuration,OrmConfig> createOrmPersistenceUnitLoader()
createOrmPersistenceUnitLoader in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>OrmPersistenceUnitLoader that can create a new persistence unit
based on an OrmConfig objectprotected String getOrmSpringSupportImplClassName()
getOrmSpringSupportImplClassName in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>OrmSpringSupport that
is used by the ORM module implementationprotected org.hibernate.Session doGetPersistenceContext(Object testObject)
OrmModuledoGetPersistenceContext in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>testObject - The test instance, not nullprotected org.hibernate.Session doGetActivePersistenceContext(Object testObject)
OrmModuledoGetActivePersistenceContext in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>testObject - The test instance, not nullprotected void flushOrmPersistenceContext(org.hibernate.Session activeSession)
OrmModuleflushOrmPersistenceContext in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>activeSession - Active persistence context, associated with the current transaction, not nullpublic void assertMappingWithDatabaseConsistent(Object testObject)
testObject - The test instance, not nullpublic Class<? extends org.hibernate.cfg.Configuration> getConfigurationObjectClass()
org.hibernate.cfg.Configuration that is used for configuring hibernateprotected org.hibernate.dialect.Dialect getDatabaseDialect(org.hibernate.cfg.Configuration configuration)
Configuration
- Parameters:
configuration - The hibernate config, not null
- Returns:
- the database Dialect, not null
-
getDataSource
protected DataSource getDataSource()
-
getTestListener
public TestListener getTestListener()
- Specified by:
getTestListener in interface Module
- Returns:
- The TestListener associated with this module
-
getDatabaseName
protected void getDatabaseName(Object testObject,
Method testMethod)
- Specified by:
getDatabaseName in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
- See Also:
OrmModule.getDatabaseName(java.lang.Object, java.lang.reflect.Method)
Copyright © 2016. All Rights Reserved.