Hibernate annotations 3.4.0.GA and slf4j?

I have a maven project that uses hibernate-annotations 3.4.0.GA, which use slf4j-api version 1.5.5 (checked through the dependency tree in the pom.xml file). Further project A indicates the version slf4j-log4j12 version 1.4.2 as a dependency.

I have another baven project depending on project A. In project B, I defined the following dependencies:

slf4j-api version 1.6.1, logback-core version 0.9.24 logback-classic version 0.9.24 

which builds fine with maven from the command line. But when I start the project from the eclipse launch configuration, I get:

 SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/mm/.m2/repository/org/slf4j/slf4j-log4j12/1.4.2/slf4j-log4j12-1.4.2.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/mm/.m2/repository/ch/qos/logback/logback-classic/0.9.24/logback-classic-0.9.24.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding. SLF4J: Your binding is version 1.5.5 or earlier. SLF4J: Upgrade your binding to version 1.6.x. or 2.0.x 

This message indicates that I need to update the binding in project A to 1.6.x, but I donโ€™t see how this is possible, since it is included in the sleep mode dependency.

Is it possible to switch the binding (updating route information) when starting project B so that instead of the version from hibernate version 1.6.1 is used?

+4
source share
2 answers

I have a maven project that uses hibernate-annotations 3.4.0.GA, which use slf4j-api version 1.5.5 (checked through the dependency tree in the pom.xml file). Further project A indicates the version slf4j-log4j12 version 1.4.2 as a dependency.

Which is not recommended, you should use the same version of slf4j artifacts. From the FAQ:

Are SLF4J versions correct?

With rare theoretical exceptions, the SLF4J variants are lagging behind compatible. This means that you can upgrade SLF4J version 1.0 to any later version without a problem.

However, although the SLF4J API is very stable from the point of view of the client, SLF4J such as slf4j-simple or slf4j-log4j12 may require the version of slf4j-api. Mixing different versions of slf4j artifacts can be problematic and very discouraged. For example, if you use slf4j-api-1.5.6.jar, then you should also use slf4j-simple-1.5.6.jar, using slf4j-simple-1.4.2.jar will not work.

At initialization time, if SLF4J suspects that there might be a version issue with a mismatch, it issues a warning about the indicated mismatch. For the exact details of the detection version mismatch, see the corresponding entry in this FAQ.

Something to fix.

which builds fine with maven from the command line. But when I start the project from the eclipse launch configuration, I get (...)

The problem is that you get SLF4J artifacts from B and from A (transitively) and you end up mixing several versions of slf4j-api (1.5.5 and 1.6.1) and several bindings ( slf4j-log4j12 and logback-classic ). SLF4J complains about a later issue at runtime, but you have to fix both.

This message indicates that I need to update the binding in project A to 1.6.x, but I donโ€™t see how this is possible, since it is included in the sleep mode dependency.

Yes, the message suggests updating the binding to a later version. But, more importantly, it says that you have more than ONE binding to the class path: you need to select log4j and logback as logging and provide the appropriate binding, but not both of them.

Is it possible to switch the binding (updating route information) when starting project B so that instead of the version from hibernate version 1.6.1 is used?

To strictly answer this question about version control in transitive dependencies, this can be done using the dependencyManagement element. Here is an example:

 <project> ... <dependencyManagement> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.1</version> </dependency> </dependencies> </dependencyManagement> ... <dependencies> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>3.4.0.GA</version> </dependency> </dependencies> ... </project> 

And artifacts with slf4j-api as a dependency, such as the Hibernate EntityManager, will use version 1.6.1, as shown below:

  $ mvn dependency: tree
 ...
 [INFO] + - org.hibernate: hibernate-entitymanager: jar: 3.4.0.GA: compile
 [INFO] |  + - org.hibernate: ejb3-persistence: jar: 1.0.2.GA: compile
 [INFO] |  + - org.hibernate: hibernate-commons-annotations: jar: 3.1.0.GA: compile
 [INFO] |  + - org.hibernate: hibernate-annotations: jar: 3.4.0.GA: compile
 [INFO] |  + - org.hibernate: hibernate-core: jar: 3.3.0.SP1: compile
 [INFO] |  |  + - antlr: antlr: jar: 2.7.6: compile
 [INFO] |  |  \ - commons-collections: commons-collections: jar: 3.1: compile
 [INFO] |  + - org.slf4j: slf4j-api: jar: 1.6.1: compile
 [INFO] |  + - dom4j: dom4j: jar: 1.6.1: compile
 [INFO] |  |  \ - xml-apis: xml-apis: jar: 1.0.b2: compile
 [INFO] |  + - javax.transaction: jta: jar: 1.1: compile
 [INFO] |  \ - javassist: javassist: jar: 3.4.GA: compile

But, as I said, the real problem is that you only need to have one binding in the classpath. Either choose log4j or logback, just not both, and specify the appropriate bindings.

+9
source

I had this problem, but after scanning my dependency tree and fixing my pompey, I still had problems. My decision?

 mvn clean 

(just in case someone made my mistake!)

0
source

All Articles