When running a project built by maven with the following dependencies:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.7.0</version>
</dependency>
I get the following error at runtime:
java.lang.SecurityException: class "javax.persistence.Cacheable"'s signer information does not match signer information of other classes in the same package
The javax.persistence-2.2.0 artifact is signed and contains the javax.persistence.Cacheable.class annotation, while the eclipselink-2.7.0 artifact is not signed and also contains the same java class annotation.
How can this be fixed?
Edit
Replacing the javax.persistence artifact version 2.2.0 by the version 2.1.1 fixes the problem (this one is not signed), but I'm not sure it's a normal situation.
To fix this issue, put in the correct JPA 2.2 compliant dependency for EclipseLink 2.7.x, in your maven pom file, as:
Thanks Stéphane - the edit at the end of your question helped me "fix" the same problem. For anyone else who hits this as well - here is an expanded answer. This is what you need to "fix" things in your pom (until Eclipse fix things properly):
This pulls in
eclipselink
but excludes thejavax.persistence
dependency that it tries to pull in and replaces it with an earlier version ofjavax.persistence
that doesn't have the signing issue.Aside:
javax.persistence
version2.2.0
is explicitly pulled in, in the pom fragment shown in the original question, despite already being a transitive dependency ofeclipselink
.Explanation
Summary - the
eclipselink
artifact depends onjavax.persistence
and both contain classes that are in the packagejavax.persistence
. However thejavax.persistence
jar is signed while theeclipselink
one is not. So the Java runtime will complain, when loading a class from the packagejavax.persistence
in theeclipselink
jar, that it's lack of signing doesn't match with classes already loaded from the same package in thejavax.persistence
jar.Details - if I put a breakpoint in
java.util.concurrent.ConcurrentHashMap.putIfAbsent(K, V)
with condition"javax.persistence".equals(arg0)
then I see thatjavax.persistence
is mapped to the followingCodeSource
value:I.e.
javax.persistence-2.2.0.jar
is signed by the Eclipse Foundation and contains classes in the packagejavax.persistence
. This jar is pulled in when some part of my application (actually something deep in Spring logic) tries to loadjavax.persistence.EntityManagerFactory
.If I then put a breakpoint in
java.lang.ClassLoader.checkCerts(String, CodeSource)
on thethrow new SecurityException
line I then see that it hits this line when the passed inCodeSource
is:I.e.
eclipselink-2.7.0.jar
also contain classes that are in thejavax.persistence
package but it is unsigned so a clash occurs that results in aSecurityException
being thrown. This happens when something (also deep in Spring logic) tries to loadjavax.persistence.PersistenceUtil
.If I look at the output of
mvn dependency:tree
I see that this mismatch seems to be down toeclipselink
itself - it is pulling inorg.eclipse.persistence:javax.persistence:jar:2.2.0
itself. I.e. it isn't some clash with some other dependency:I've logged this now at bugs.eclipse.org - see bug 525457.
Obinna's answer is correct; I guess that there was an issue with eclipselink 2.7.x –as George indicated. I had a similar issue when upgrading eclipselink, but it was just wrong artefacts. The initially described issue seems to be a result of externally referencing javax.persistence level - it is definitely not necessary.
Proper maven configuration can be found in eclipselink wiki: https://wiki.eclipse.org/EclipseLink/Maven
I also run into this problem, with my case being a bit different, in that I am not using Maven. However, I place an answer here, as it might give people an idea about how to deal with this in their own situation. After all, the title is about this mismatch, in general, one sub-case being when using Maven.
I am using eclipselink in a NetBeans project. Initially, I was placing both the the eclipselink jar file (
eclipselink-2.7.0.jar
) and the needed org.eclipse.persistence jar files as external libraries to my project. Comments by Sergey and entreprenr above are what actually lead me to solve my problem. What I had to do was create a new library (Tools->Libraries->New Library...) which does not contain the eclipselink jar file (i.e.eclipselink-2.7.0.jar
is not added in the library), only the specific org.eclipse.persistence jar files that are necessary for the project, e.g.org.eclipse.persistence.antlr-2.7.0.jar
,org.eclipse.persistence.asm-2.7.0.jar
,org.eclipse.persistence.core-2.7.0.jar
,org.eclipse.persistence.jpa.modelgen.processor-2.7.0.jar
,org.eclipse.persistence.jpa-2.7.0.jar
, etc. I then added this library to my project and the exception vanished.Of course, I also had to replace all org.eclipse.persistence jar files on my server with their 2.7.0 version and also replace the
javax.persistence.jar
with its 2.2.0 version (I use payara, so these are located under<payara_home>\glassfish\modules
).I fixed this by switching the order in which the jars appear in the classpath. In my case, I'm using Tomcat and had to modify catalina.properties to put javax before eclipselink.
eclipselink.jar as such is designed as all-in-one bundle, not osgi enabled jar containing all partsof eclipselink project (ie sdo, oracle db specific stuff, dbws, nosql..) with ability to run with jpa api 2.0 on the classpath - at least in 2.x versions. In many cases this is not needed and proper components can be used instead, such as org.eclipse.persistence.jpa, org.eclipse.persistence.oracle etc. For the full list see ie: http://search.maven.org/#search%7Cga%7C1%7Corg.eclipse.persistence