HHH-6964 EnversIntegrator is always detected by default while initializing Serviceregistry using Native Hibernate API causing a MappingException even when Envers is not used
This commit is contained in:
parent
e07aff45da
commit
8f9d8b530e
|
@ -22,6 +22,7 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.envers.configuration;
|
package org.hibernate.envers.configuration;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
@ -89,25 +90,30 @@ public class AuditConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuditConfiguration(Configuration cfg) {
|
public AuditConfiguration(Configuration cfg) {
|
||||||
this(cfg, null);
|
this( cfg, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuditConfiguration(Configuration cfg, ClassLoaderService classLoaderService) {
|
public AuditConfiguration(Configuration cfg, ClassLoaderService classLoaderService) {
|
||||||
Properties properties = cfg.getProperties();
|
Properties properties = cfg.getProperties();
|
||||||
|
|
||||||
ReflectionManager reflectionManager = cfg.getReflectionManager();
|
ReflectionManager reflectionManager = cfg.getReflectionManager();
|
||||||
globalCfg = new GlobalConfiguration(properties);
|
globalCfg = new GlobalConfiguration( properties );
|
||||||
RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration(globalCfg);
|
RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration( globalCfg );
|
||||||
RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(cfg, reflectionManager);
|
RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure( cfg, reflectionManager );
|
||||||
auditEntCfg = new AuditEntitiesConfiguration(properties, revInfoCfgResult.getRevisionInfoEntityName());
|
auditEntCfg = new AuditEntitiesConfiguration( properties, revInfoCfgResult.getRevisionInfoEntityName() );
|
||||||
auditProcessManager = new AuditProcessManager(revInfoCfgResult.getRevisionInfoGenerator());
|
auditProcessManager = new AuditProcessManager( revInfoCfgResult.getRevisionInfoGenerator() );
|
||||||
revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator();
|
revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator();
|
||||||
revisionInfoNumberReader = revInfoCfgResult.getRevisionInfoNumberReader();
|
revisionInfoNumberReader = revInfoCfgResult.getRevisionInfoNumberReader();
|
||||||
modifiedEntityNamesReader = revInfoCfgResult.getModifiedEntityNamesReader();
|
modifiedEntityNamesReader = revInfoCfgResult.getModifiedEntityNamesReader();
|
||||||
this.classLoaderService = classLoaderService;
|
this.classLoaderService = classLoaderService;
|
||||||
auditStrategy = initializeAuditStrategy(revInfoCfgResult.getRevisionInfoClass(),
|
auditStrategy = initializeAuditStrategy(
|
||||||
revInfoCfgResult.getRevisionInfoTimestampData());
|
revInfoCfgResult.getRevisionInfoClass(),
|
||||||
entCfg = new EntitiesConfigurator().configure(cfg, reflectionManager, globalCfg, auditEntCfg, auditStrategy,
|
revInfoCfgResult.getRevisionInfoTimestampData()
|
||||||
revInfoCfgResult.getRevisionInfoXmlMapping(), revInfoCfgResult.getRevisionInfoRelationMapping());
|
);
|
||||||
|
entCfg = new EntitiesConfigurator().configure(
|
||||||
|
cfg, reflectionManager, globalCfg, auditEntCfg, auditStrategy,
|
||||||
|
revInfoCfgResult.getRevisionInfoXmlMapping(), revInfoCfgResult.getRevisionInfoRelationMapping()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuditStrategy initializeAuditStrategy(Class<?> revisionInfoClass, PropertyData revisionInfoTimestampData) {
|
private AuditStrategy initializeAuditStrategy(Class<?> revisionInfoClass, PropertyData revisionInfoTimestampData) {
|
||||||
|
@ -116,23 +122,28 @@ public class AuditConfiguration {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Class<?> auditStrategyClass = null;
|
Class<?> auditStrategyClass = null;
|
||||||
if(classLoaderService!=null){
|
if ( classLoaderService != null ) {
|
||||||
auditStrategyClass = classLoaderService.classForName( auditEntCfg.getAuditStrategyName() );
|
auditStrategyClass = classLoaderService.classForName( auditEntCfg.getAuditStrategyName() );
|
||||||
} else {
|
}
|
||||||
auditStrategyClass = Thread.currentThread().getContextClassLoader().loadClass(auditEntCfg.getAuditStrategyName());
|
else {
|
||||||
|
auditStrategyClass = Thread.currentThread()
|
||||||
|
.getContextClassLoader()
|
||||||
|
.loadClass( auditEntCfg.getAuditStrategyName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
strategy = (AuditStrategy) auditStrategyClass.newInstance();
|
strategy = (AuditStrategy) auditStrategyClass.newInstance();
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch ( Exception e ) {
|
||||||
throw new MappingException(
|
throw new MappingException(
|
||||||
String.format("Unable to create AuditStrategy[%s] instance." , auditEntCfg.getAuditStrategyName()),
|
String.format( "Unable to create AuditStrategy[%s] instance.", auditEntCfg.getAuditStrategyName() ),
|
||||||
e);
|
e
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strategy instanceof ValidityAuditStrategy) {
|
if ( strategy instanceof ValidityAuditStrategy ) {
|
||||||
// further initialization required
|
// further initialization required
|
||||||
Getter revisionTimestampGetter = ReflectionTools.getGetter(revisionInfoClass, revisionInfoTimestampData);
|
Getter revisionTimestampGetter = ReflectionTools.getGetter( revisionInfoClass, revisionInfoTimestampData );
|
||||||
((ValidityAuditStrategy) strategy).setRevisionTimestampGetter(revisionTimestampGetter);
|
( (ValidityAuditStrategy) strategy ).setRevisionTimestampGetter( revisionTimestampGetter );
|
||||||
}
|
}
|
||||||
|
|
||||||
return strategy;
|
return strategy;
|
||||||
|
@ -146,12 +157,13 @@ public class AuditConfiguration {
|
||||||
public synchronized static AuditConfiguration getFor(Configuration cfg) {
|
public synchronized static AuditConfiguration getFor(Configuration cfg) {
|
||||||
return getFor( cfg, null );
|
return getFor( cfg, null );
|
||||||
}
|
}
|
||||||
public synchronized static AuditConfiguration getFor(Configuration cfg, ClassLoaderService classLoaderService) {
|
|
||||||
AuditConfiguration verCfg = cfgs.get(cfg);
|
|
||||||
|
|
||||||
if (verCfg == null) {
|
public synchronized static AuditConfiguration getFor(Configuration cfg, ClassLoaderService classLoaderService) {
|
||||||
verCfg = new AuditConfiguration(cfg, classLoaderService);
|
AuditConfiguration verCfg = cfgs.get( cfg );
|
||||||
cfgs.put(cfg, verCfg);
|
|
||||||
|
if ( verCfg == null ) {
|
||||||
|
verCfg = new AuditConfiguration( cfg, classLoaderService );
|
||||||
|
cfgs.put( cfg, verCfg );
|
||||||
|
|
||||||
cfg.buildMappings();
|
cfg.buildMappings();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue