Post-compile enhancement fails when static Log4j 2.5 based logger used in Entity


I doubt this is an ObjectDB-enhancer problem, I am however reporting it in case anybody else encounters the problem too. It is mostly also not a concern for my own web app, because in most cases a non-static logging variable holder can be used in an @Entity.

    ObjectDB 2.6.3_04

    Apache Log4j2 - 2.5

    Mac OS X

    jdk1.7.0_51 or jdk1.8.0_60

    NetBeans 8.1Beta

I created a log4j2 LoggerWrapper using the technique described under the Log4j2 manual: Generating Source Code for a Custom Logger Wrapper (otherwise not shown here, see that link for examples). My LoggerWrapper offers a cache of loggers keyed to classes for lookup:

 public final class LoggerWrapper extends ExtendedLoggerWrapper {

 private static final Map<Class,LoggerWrapper> loggerWrappers = new HashMap<Class,LoggerWrapper>();  

    static public LoggerWrapper findLoggerWrapperFor(Class clazz) {
        if (loggerWrappers.containsKey(clazz)) return loggerWrappers.get(clazz);
        LoggerWrapper l = LoggerWrapper.create(clazz.getName());
        return l;

If I use that in an @Entity for a static logger variable:

public class Element extends [] implements []

static final private LoggerWrapper LOGGER = LoggerWrapper.findLoggerWrapperFor(Element.class);

For some reason the error is reported on a subtype:


public class SubEntity extends Element {

On post-compile enhancement I get this error (as reported in the odb log file):

[ObjectDB 2.6.3_04] Failed to process class file of type 'com.example.SubEntity' (error 422)
com.objectdb.o.UserException: Failed to process class file of type 'com.example.SubEntity'
at com.objectdb.o.MSG.d(
at com.objectdb.o.JEL.A(
at com.objectdb.o.JEN.m(
at com.objectdb.Enhancer.main(
Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "org/xml/sax/InputSource"
at org.apache.logging.log4j.core.config.xml.XmlConfiguration.(

In the build.xml Ant script for the post-compile enhancement the class path is:


If I comment out that static LOGGER variable init line, the error vanishes and post-compile enhancement works.


It seems like a class loading conflict.

This will be solved in future Enhancer versions by avoiding class loading during enhancement.

If you have a longer stack trace in the log it may help.

ObjectDB Support

Build 2.6.6_05 should fix the issue. Thank you for this report.

ObjectDB Support