Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Hibernate + log4j2 + JPA + Maven: missing dependency
PostPosted: Wed Aug 30, 2017 6:12 am 
Newbie

Joined: Wed Aug 30, 2017 6:01 am
Posts: 2
In the case you receive

Code:
Exception in thread "main" org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [org.apache.logging.log4j.core.appender.db.jpa.converter.ContextDataJsonAttributeConverter]
        at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:351)
        at org.hibernate.boot.model.process.internal.ScanningCoordinator.applyScanResultsToManagedResources(ScanningCoordinator.java:235)
        at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:81)
        at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:98)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:228)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:170)
        at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:76)
        at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:181)
        at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:129)
        at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:71)
        at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:52)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
        at com.boraji.tutorial.hibernate.MainApp.byJpa(MainApp.java:58)
        at com.boraji.tutorial.hibernate.MainApp.main(MainApp.java:24)
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
        at org.apache.logging.log4j.core.appender.db.jpa.converter.ContextDataJsonAttributeConverter.<clinit>(ContextDataJsonAttributeConverter.java:47)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Unknown Source)
        at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:345)
        ... 14 more
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        ... 18 more


To fix it, modify your pom.xml.

Add

Code:
      <dependency>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-databind</artifactId>
         <version>2.9.0</version>
         <scope>runtime</scope>
      </dependency>


around

Code:
      <dependency>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate-core</artifactId>
         <version>5.2.10.Final</version>
      </dependency>


Curiosly, it does not happen when you run your code in Eclipse!

For me, this is a bug in the Maven dependencies by Hibernate.


Top
 Profile  
 
 Post subject: Re: Hibernate + log4j2 + JPA + Maven: missing dependency
PostPosted: Wed Aug 30, 2017 7:06 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1433
Quote:
For me, this is a bug in the Maven dependencies by Hibernate.


Nope, it's not.

If you run mvn dependency:tree, you'll get something like this:

Code:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ high-performance-java-persistence-core ---
[INFO] +- org.hibernate:hibernate-core:jar:5.2.11-SNAPSHOT:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  +- org.javassist:javassist:jar:3.20.0-GA:compile
[INFO] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.1.Final:compile
[INFO] |  +- org.jboss:jandex:jar:2.0.3.Final:compile
[INFO] |  +- com.fasterxml:classmate:jar:1.3.0:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile


So, as you can clearly see, there's no trace of jackson-databind dependency.

More, there's no occurrence for jackson-databind on GitHub as well.

The stack-trace is very accurate about the actual cause for your issue:

Code:
at org.apache.logging.log4j.core.appender.db.jpa.converter.ContextDataJsonAttributeConverter.<clinit>(ContextDataJsonAttributeConverter.java:47)


It's because of the Log4j ContextDataJsonAttributeConverter that you need jackson-databind.

Cheers!

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Hibernate + log4j2 + JPA + Maven: missing dependency
PostPosted: Wed Aug 30, 2017 3:53 pm 
Newbie

Joined: Wed Aug 30, 2017 6:01 am
Posts: 2
You misunderstood me except in your last sentence: the dependency is missing!

I didnˋt do a more detailed analysis how to fix the problem eternaly. It's in the interplay between log4j, Hibernate and JPA in a very specific way.

Any maintainer is welcomed to supply a solution!


Top
 Profile  
 
 Post subject: Re: Hibernate + log4j2 + JPA + Maven: missing dependency
PostPosted: Wed Aug 30, 2017 3:57 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1433
Quote:
Any maintainer is welcomed to supply a solution!


I guess you should ask the log4j maintainers to fix the missing dependency since ContextDataJsonAttributeConverter is their class, not ours.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.