Wednesday 3 July 2019

JPA: Trouble Shooting


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

When I am setting up jpa project with Eclipse Link + Apache Derby, I faced below problem.
Exception in thread "main" java.lang.SecurityException: class "javax.persistence.PersistenceUtil"'s signer information does not match signer information of other classes in the same package
 at java.lang.ClassLoader.checkCerts(ClassLoader.java:898)
 at java.lang.ClassLoader.preDefineClass(ClassLoader.java:668)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:761)
 at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
 at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
 at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
 at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
 at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
 at com.sample.app.Test.main(Test.java:14)

It is because, I added below maven dependency to my project.

                  <!-- https://mvnrepository.com/artifact/org.eclipse.persistence/eclipselink -->
                  <dependency>
                           <groupId>org.eclipse.persistence</groupId>
                           <artifactId>eclipselink</artifactId>
                           <version>2.7.1</version>
                  </dependency>


I resolved the problem by excluding the ‘javax.persistence’ API, that comes as part of Eclipse Link and adding the persistence API explicitly like below.
  <!-- https://mvnrepository.com/artifact/org.eclipse.persistence/eclipselink -->
  <dependency>
   <groupId>org.eclipse.persistence</groupId>
   <artifactId>eclipselink</artifactId>
   <version>2.7.1</version>
   <exclusions>
    <exclusion>
     <groupId>org.eclipse.persistence</groupId>
     <artifactId>javax.persistence</artifactId>
    </exclusion>
   </exclusions>
  </dependency>

  <!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
  <dependency>
   <groupId>javax.persistence</groupId>
   <artifactId>javax.persistence-api</artifactId>
   <version>2.2</version>
  </dependency>

PersistenceException: No Persistence provider for EntityManager named 

When I am setting up JPA project with Eclipse Link + Apache Derby, I faced below problem.
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named demoDatabasePersistenceUnit
 at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
 at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
 at com.sample.app.Test.main(Test.java:14)


I resolved above problem by adding ‘persistence.xml’ file folder of src/main/resources/META-INF folder.

persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
 xmlns="http://java.sun.com/xml/ns/persistence"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
 <persistence-unit name="demoDatabasePersistenceUnit"
  transaction-type="RESOURCE_LOCAL">
  <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

  <class>com.smaple.entities.Employee</class>

  <properties>
   <property name="eclipselink.target-database" value="Derby" />
   <property name="javax.persistence.jdbc.driver"
    value="org.apache.derby.jdbc.ClientDriver" />
   <property name="javax.persistence.jdbc.url"
    value="jdbc:derby://localhost:1527/demoDatabase;create=true" />
   <property name="javax.persistence.jdbc.user" value="APP" />
   <property name="javax.persistence.jdbc.password" value="APP" />
   <property name="eclipselink.logging.level" value="ALL" />

   <property name="eclipselink.ddl-generation"
    value="drop-and-create-tables" />

   <property name="eclipselink.ddl-generation.output-mode"
    value="database" />
  </properties>

 </persistence-unit>
</persistence>


org.eclipse.persistence.exceptions.DatabaseException

Exception Description: Configuration error.  Class [org.apache.derby.jdbc.ClientDriver] not found.

When I am setting up JPA project with Eclipse Link + Apache Derby, I faced below problem.
Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.7.1.v20171221-bd47e8f): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error.  Class [org.apache.derby.jdbc.ClientDriver] not found.
 at org.eclipse.persistence.exceptions.DatabaseException.configurationErrorClassNotFound(DatabaseException.java:89)
 at org.eclipse.persistence.sessions.DefaultConnector.loadDriverClass(DefaultConnector.java:267)
 at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:85)
 at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:170)
 at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connectInternal(DatasourceAccessor.java:346)
 at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.connectInternal(DatabaseAccessor.java:313)
 at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connect(DatasourceAccessor.java:434)
 at org.eclipse.persistence.sessions.server.ConnectionPool.buildConnection(ConnectionPool.java:217)
 at org.eclipse.persistence.sessions.server.ConnectionPool.startUp(ConnectionPool.java:505)
 at org.eclipse.persistence.sessions.server.ServerSession.connect(ServerSession.java:519)
 at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:819)
 at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:256)
 at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:759)
 at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:216)
 at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:324)
 at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:348)
 at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:311)
 at com.sample.app.Test.main(Test.java:16)


I resolved above problem by adding derby client driver to pom.xml file.

 <dependencies>
  <!-- https://mvnrepository.com/artifact/org.eclipse.persistence/eclipselink -->
  <dependency>
   <groupId>org.eclipse.persistence</groupId>
   <artifactId>eclipselink</artifactId>
   <version>2.7.1</version>
   <exclusions>
    <exclusion>
     <groupId>org.eclipse.persistence</groupId>
     <artifactId>javax.persistence</artifactId>
    </exclusion>
   </exclusions>
  </dependency>

  <!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
  <dependency>
   <groupId>javax.persistence</groupId>
   <artifactId>javax.persistence-api</artifactId>
   <version>2.2</version>
  </dependency>

  <!-- https://mvnrepository.com/artifact/org.apache.derby/derbyclient -->
  <dependency>
   <groupId>org.apache.derby</groupId>
   <artifactId>derbyclient</artifactId>
   <version>10.14.2.0</version>
  </dependency>

 </dependencies>



Previous                                                    Next                                                    Home

No comments:

Post a Comment