339 words

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

2016-02-15 01:07

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(MSG.java:75)
at com.objectdb.o.JEL.A(JEL.java:446)
at com.objectdb.o.JEN.m(JEN.java:101)
at com.objectdb.Enhancer.main(Enhancer.java:33)
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 com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:237)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:348)
at org.apache.logging.log4j.core.config.xml.XmlConfiguration.(XmlConfiguration.java:97)

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.

--- Webel IT Australia, "The Elements of the Web", Specialists in model-based UML, SysML, Enterprise Java, XML, and Drupal CMS web engineering. Dr Darren Kelly, BSc, PhD, https://www.webel.com.au
webel's picture
Joined on 2011-05-27
User Post #82
2016-02-15 21:18

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support's picture
Joined on 2010-05-03
User Post #2,429
2016-02-16 17:32

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

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support's picture
Joined on 2010-05-03
User Post #2,432

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Maximum file size: 32 MB