39
39
import org .hibernate .envers .strategy .ValidityAuditStrategy ;
40
40
import org .hibernate .envers .synchronization .AuditProcessManager ;
41
41
import org .hibernate .envers .tools .reflection .ReflectionTools ;
42
+ import org .hibernate .internal .util .ClassLoaderHelper ;
42
43
import org .hibernate .internal .util .ReflectHelper ;
43
44
import org .hibernate .property .Getter ;
44
45
import org .hibernate .service .classloading .spi .ClassLoaderService ;
@@ -95,6 +96,11 @@ public AuditConfiguration(Configuration cfg) {
95
96
}
96
97
97
98
public AuditConfiguration (Configuration cfg , ClassLoaderService classLoaderService ) {
99
+ // TODO: Temporarily allow Envers to continuing using
100
+ // hibernate-commons-annotations' for reflection and class loading.
101
+ ClassLoader tccl = Thread .currentThread ().getContextClassLoader ();
102
+ Thread .currentThread ().setContextClassLoader ( ClassLoaderHelper .getContextClassLoader () );
103
+
98
104
Properties properties = cfg .getProperties ();
99
105
100
106
ReflectionManager reflectionManager = cfg .getReflectionManager ();
@@ -115,6 +121,8 @@ public AuditConfiguration(Configuration cfg, ClassLoaderService classLoaderServi
115
121
cfg , reflectionManager , globalCfg , auditEntCfg , auditStrategy ,
116
122
revInfoCfgResult .getRevisionInfoXmlMapping (), revInfoCfgResult .getRevisionInfoRelationMapping ()
117
123
);
124
+
125
+ Thread .currentThread ().setContextClassLoader ( tccl );
118
126
}
119
127
120
128
private AuditStrategy initializeAuditStrategy (Class <?> revisionInfoClass , PropertyData revisionInfoTimestampData ) {
@@ -123,11 +131,16 @@ private AuditStrategy initializeAuditStrategy(Class<?> revisionInfoClass, Proper
123
131
try {
124
132
125
133
Class <?> auditStrategyClass = null ;
126
- if ( classLoaderService != null ) {
127
- auditStrategyClass = classLoaderService . classForName ( auditEntCfg .getAuditStrategyName () );
134
+ try {
135
+ auditStrategyClass = this . getClass (). getClassLoader (). loadClass ( auditEntCfg .getAuditStrategyName () );
128
136
}
129
- else {
130
- auditStrategyClass = ReflectHelper .classForName ( auditEntCfg .getAuditStrategyName () );
137
+ catch (Exception e ) {
138
+ if ( classLoaderService != null ) {
139
+ auditStrategyClass = classLoaderService .classForName ( auditEntCfg .getAuditStrategyName () );
140
+ }
141
+ else {
142
+ auditStrategyClass = ReflectHelper .classForName ( auditEntCfg .getAuditStrategyName () );
143
+ }
131
144
}
132
145
133
146
strategy = (AuditStrategy ) ReflectHelper .getDefaultConstructor (auditStrategyClass ).newInstance ();
0 commit comments