4

When I try to create an EntityManager, I get this exception:

java.lang.SecurityException: class "javax.persistence.PersistenceUtil"'s signer information does not match signer information of other classes in the same package

Perhaps it is something with the javax.persistence packages but I don't know how can I fix it.

    public static EntityManager getEntityManager() {
    if(emf == null) {
        emf = Persistence.createEntityManagerFactory("AccountsManager");
    }
    return emf.createEntityManager();
}

Here is the persistence.xml file

  <?xml version="1.0" encoding="UTF-8"?>
  <persistence version="2.1" 
  xmlns="http://xmlns.jcp.org/xml/ns/persistence" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence 
   http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="AccountsManager" transaction- 
                                  type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>model.Account</class>
    <class>model.AllSubscription</class>
    <class>model.Client</class>
</persistence-unit>

I found similar questions but I didn't find any solutions.

Dexxrey
  • 183
  • 1
  • 14

2 Answers2

4

After I have read all possible similar topics I figured it out.

In the current version of eclipselink(2.7.4) if you add jakarta.persistence_2.2.2.jar alongside with eclipselink.jar this problem occurs. Both jars have some classes and packages with the same name. In order to fix that you have to add jakarta.persistence_2.2.2.jar before the eclipselink.jar. So all the classes are taken from the jakarta not partly.

I don't fully understand how these two libraries interact with each other, but replacing the order in the build path helped.

Dexxrey
  • 183
  • 1
  • 14
1

Replace jakarta.persistence_2.2.2.jar for jakarta.persistence-2.2.3.jar from maven repository.

  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). – geisterfurz007 Oct 01 '19 at 13:21