javax.persistence.PersistenceException by using createEntityManagerFactory - java

My following code is working on my Windows, but does not working on my Linux Mint. A added all libraries that are relevant.
I get this exception for the createEntityManagerFactory row:
javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "JPA_probaPU" after trying the following discovered implementations: org.eclipse.persistence.jpa.PersistenceProvider from provider: org.eclipse.persistence.jpa.PersistenceProvider
My java file:
package jpa_proba;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.eclipse.persistence.exceptions.EntityManagerSetupException;
public class JPA_proba {
public static void main(String[] args) {
try{
EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPA_probaPU");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
//Integer id, String isbn, String szerzo, String cim, String mufaj, int ar, int elerheto
Konyv k = new Konyv(null, "654654444444", "Kiss Béla", "Hogyan ne csináljunk semmit?", "dráma", 500, 1);
em.persist(k);
em.getTransaction().commit();
}
catch(Exception ex){
System.out.println(ex);
}
}
}
My persistence.xml:
<?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="JPA_probaPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>jpa_proba.Konyv</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/helix1?zeroDateTimeBehavior=convertToNull"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.password" value="123456"/>
</properties>
</persistence-unit>
</persistence>
Errors:
Exception in thread "main" javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "JPA_probaPU" after trying the following discovered implementations: org.eclipse.persistence.jpa.PersistenceProvider from provider: org.eclipse.persistence.jpa.PersistenceProvider
at javax.persistence.Persistence.createPersistenceException(Persistence.java:244)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:186)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:72)
at jpa_proba.JPA_proba.main(JPA_proba.java:13)
Caused by: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoad er#5caf905d
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [JPA_probaPU] failed.
Internal Exception: java.lang.IncompatibleClassChangeError: Implementing class
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:107)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:152)

You are getting Internal Exception: java.lang.IncompatibleClassChangeError: Implementing class.
This might occur when you have more than one version of same class/jar.

Related

EclipseLink: createNativeQuery exeption - org.postgresql.util.PSQLException

I'm running into a weird issue that hasn't been reported by others from what I could tell, there may be a bug when using createNativeQuery. I have tried so many things to understand why to no avail.
Current Environment:
EclipseLink 2.7.3 JPA provider
PostgreSQL 10.6.1 Database
Eclipse Photon IDE
JRE 1.8.0_121
When executing:
Long total = (Long) em.createNativeQuery("Project.count").getSingleResult();
It's throwing the following:
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: syntax error at or near "Project"
Position: 1
Error Code: 0
Call: Project.count
Query: DataReadQuery(sql="Project.count")
at org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:391)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:264)
at org.eclipse.persistence.internal.jpa.QueryImpl.getSingleResult(QueryImpl.java:530)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:404)
at com.bbandt.util.testers.ProjectTester.ProjectVersionMapping(ProjectTester.java:43)
at com.bbandt.util.testers.ProjectTester.main(ProjectTester.java:21)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: syntax error at or near "Project"
Position: 1
Error Code: 0
Call: Project.count
Query: DataReadQuery(sql="Project.count")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:342)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:691)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:567)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2096)
at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:603)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:275)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:261)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:332)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelect(DatasourceCallQueryMechanism.java:314)
at org.eclipse.persistence.queries.DataReadQuery.executeNonCursor(DataReadQuery.java:199)
at org.eclipse.persistence.queries.DataReadQuery.executeDatabaseQuery(DataReadQuery.java:154)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:914)
at org.eclipse.persistence.queries.DataReadQuery.execute(DataReadQuery.java:139)
at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:813)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2981)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1895)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1877)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1842)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:262)
... 4 more
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "Project"
Position: 1
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:106)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:1015)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:651)
... 21 more
Persistence.xml (truncated purposely )
<?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="LocalPostgreSQL" transaction-type="RESOURCE_LOCAL">
<mapping-file>META-INF/orm.xml</mapping-file>
<mapping-file>META-INF/Queries.xml</mapping-file>
<!-- <mapping-file>META-INF/ResultsetMappings.xml</mapping-file>
-->
<class>com.bbandt.jpa.converters.UUIDAttributeConverter</class>
<class>model.Component</class>
<class>model.ComponentVulnerability</class>
<class>model.ComponentVulnerabilityPK</class>
<class>model.Project</class>
<class>model.ProjectVersion</class>
<class>model.ProjectVersionPK</class>
ORM.xml contents:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd">
<named-native-query name="Project.count">
<query>Select count(*) as total from public.project</query>
</named-native-query>
</entity-mappings>
From what I could tell, the named native query is not getting resolved back to the actual SQL contents.
Executing this works (and it resolves the named-native-query name "Project.count"):
Long total = (Long) em.createNamedQuery("Project.count").getSingleResult();
This also works:
Long total = (Long) em.createNativeQuery("Select count(*) from project").getSingleResult();
I didn't want to resort to JPQL for other reasons unimportant to this thread and I also need to implement SQL Resultset Mappings.
Any insight on this would be greatly appreciated. I truly ran out of ideas.
createNamedQuery: Used to define queries wthe ith name in mapping file or annotation
createNativeQuery: Used to execute native/pure SQL queries
Since you use createNativeQuery method with a named query you are getting above error

How to handle 'IllegalBlockSizeException' when creating EntityManager with EclipseLink version 2.6.4?

I'm using EclipseLink and Java Persistence API to connect to local database, however when I'm creating EntityManager object, I'm getting following error:
[EL Severe]: ejb: 2017-06-04 19:29:55.066--ServerSession(1644987969)--Exception [EclipseLink-7107] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Error encountered during string decryption.
Internal Exception: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-7107] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Error encountered during string decryption.
Internal Exception: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
Error stack trace point at line where I create EntityManager:
private EntityManagerFactory factory;
private EntityManager em;
public JpaDatabaseConnection() {
factory = Persistence.createEntityManagerFactory("blogspace");
em = factory.createEntityManager();
}
I've added eclipselink and java persistence API through Maven Dependencies and JDBC driver to project classpath. This is my persistence.xml file (located in META-INF directory in folder with project packages):
<?xml version="1.0" encoding="UTF-8" ?>
<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"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="blogspace" transaction-type="RESOURCE_LOCAL">
<class>pl.furman.server.database.entities.User</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost/blogspace" />
<property name="javax.persistence.jdbc.user" value="blogserver" />
<property name="javax.persistence.jdbc.password" value="123456" />
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
</persistence>
What is the cause of problem and how it can be solved? I know that JDBC driver itself probably is working correctly because when I intentionally put wrong password into persistence.xml file I'm getting error about failed authorization. Database is set up and working because I can create queries and insert data into database from shell and from eclipse toad extension.
Thank you in advance for help.
Edit: Problem lies in user name and/or password in persistence.xml. When I changed it to user and password of different length, connection works without problems. However still I have no idea why that was happening.
I can confirm the odd behaviour with EclipseLink version 2.6.4, as I reproduced your setup . Here's the full stack trace:
Internal Exception: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:815)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:205)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:305)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:337)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:303)
at demo.service.UserService.<init>(UserService.java:14)
at demo.Runner.main(Runner.java:8)
Caused by: Exception [EclipseLink-7107] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Error encountered during string decryption.
Internal Exception: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
at org.eclipse.persistence.exceptions.ValidationException.errorDecryptingPassword(ValidationException.java:894)
at org.eclipse.persistence.internal.security.JCEEncryptor.decryptPassword(JCEEncryptor.java:114)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.updateLogins(EntityManagerSetupImpl.java:2404)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.updateSession(EntityManagerSetupImpl.java:2716)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:710)
... 6 more
Caused by: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:934)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:845)
at com.sun.crypto.provider.DESCipher.engineDoFinal(DESCipher.java:314)
at javax.crypto.Cipher.doFinal(Cipher.java:2165)
at org.eclipse.persistence.internal.security.JCEEncryptor.decryptPassword(JCEEncryptor.java:109)
... 9 more
It seems, this relates to a bug in org.eclipse.persistence.internal.security.JCEEncryptor. While debugging, I found that there are certain password lengths which cause the observed behaviour, e.g. for 123456.
Solution
Now the good part of my answer: This bug was fixed with version 2.6.5-RC1. Moreover, it also works as expected with the latest 2.6.5-RC2 release candidate (available since June 2017). In case you have a Maven project, change the version string of the EclipseLink dependency like so:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.5-RC2</version>
</dependency>
If this is a standalone project, find the latest 2.6.5-RC2 jar file on Maven Central. Just remove the old jar file and put the new one in the application's class path.
Btw, when I changed the PW to 123456789 in the database as well as in persistence.xml it worked even with the bugged version 2.6.4. Odd, isn't it?
Hope it helps.

Cannot acquire data source whit PostgreSql. Can't use JPA EntityManager

I have the next problem:
I am doing a project using JPA and Restfull whit netbeasn and postgres, I have the following persistence
<?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="PruebaPersitenciaPU" transaction-type="JTA">
<jta-data-source>data_cotratacion</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
And also the following code using the EntityManager:
#GET
public String crearPersona(
#QueryParam("id") String id,
#QueryParam("name") String name,
#QueryParam("gender") String gender,
#QueryParam("date") String date){
Persona p = new Persona();
p.setId(id);
p.setName(name);
p.setGender(gender);
p.setDate(stringToDate(date));
try {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("PruebaPersitenciaPU");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(p);
em.getTransaction().commit();
return "Usuario Creado "+id;
} catch (Exception e) {
return "Usuario no creado error: "+e;
}
}
but try this sends me this error:
Usuario no creado error: javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException Exception Description: Cannot acquire data source [data_cotratacion]. Internal Exception: javax.naming.NamingException: Lookup failed for 'data_cotratacion' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: data_cotratacion not found]
Sounds like there is no JDBC datasource configured with the name data_cotratacion. You need to configure this JDBC resource on your application server.
Or you need to create your persistence unit by using the wizard in netbeans go in the menu to File > New File Then select Persistence in the left box and Persistence Unit in the right box.

Intellij 13 EclipseLink Class [] not found Error

i ve a huge problem with intellij 13.0.1. I set up a JPA Project for the first time in intellij 13 and need some help to get some rid of an strange error.
Caused by: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [] not found.
I added a persistence Unit and add the datasource, if i test the connection it is successfull. I also added eclipselink in version 2.5.1 and postgres.jdbc.driver in 9.3-1100. I also installed Postgres # latest build. I get the error if i want to create an Entitymanager. Any idea what i could do to get rid of this error?
src:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("RoomDB");
EntityManager em = emf.createEntityManager(); //<- Configuration Error
em.getTransaction().begin();
User user1 = new User();
user1.setUsername("testuser");
user1.setPassword("testuser");
em.persist(user1);
Room room1 = new Room();
room1.setRoom_nr(12);
em.persist(room1);
em.getTransaction().commit();
em.close();
Stack-Trace:
[EL Info]: transaction: 2013-12-30 23:16:13.05--ServerSession(20030435)--property eclipselink.jdbc.user is deprecated, property javax.persistence.jdbc.user should be used instead.
[EL Info]: transaction: 2013-12-30 23:16:13.062--ServerSession(20030435)--property eclipselink.jdbc.driver is deprecated, property javax.persistence.jdbc.driver should be used instead.
[EL Info]: transaction: 2013-12-30 23:16:13.062--ServerSession(20030435)--property eclipselink.jdbc.url is deprecated, property javax.persistence.jdbc.url should be used instead.
[EL Info]: transaction: 2013-12-30 23:16:13.062--ServerSession(20030435)--property eclipselink.jdbc.password is deprecated, property javax.persistence.jdbc.password should be used instead.
[EL Info]: transaction: 2013-12-30 23:16:13.949--ServerSession(20030435)--property eclipselink.jdbc.user is deprecated, property javax.persistence.jdbc.user should be used instead.
[EL Info]: transaction: 2013-12-30 23:16:13.949--ServerSession(20030435)--property eclipselink.jdbc.driver is deprecated, property javax.persistence.jdbc.driver should be used instead.
[EL Info]: transaction: 2013-12-30 23:16:13.95--ServerSession(20030435)--property eclipselink.jdbc.url is deprecated, property javax.persistence.jdbc.url should be used instead.
[EL Info]: transaction: 2013-12-30 23:16:13.95--ServerSession(20030435)--property eclipselink.jdbc.password is deprecated, property javax.persistence.jdbc.password should be used instead.
[EL Info]: 2013-12-30 23:16:15.632--ServerSession(20030435)--EclipseLink, version: Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5
[EL Severe]: ejb: 2013-12-30 23:16:15.639--ServerSession(20030435)--Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [] not found.
Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [] not found.
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:766)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:182)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getDatabaseSession(EntityManagerFactoryImpl.java:527)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:140)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at de.Enviroment.main(Enviroment.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [] 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:162)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:204)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:741)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
... 13 more
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="RoomDB">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>de.Entity.Room</class>
<class>de.Entity.User</class>
<properties>
<property name="eclipselink.jdbc.url" value=""/>
<property name="eclipselink.jdbc.driver" value=""/>
<property name="eclipselink.jdbc.user" value=""/>
<property name="eclipselink.jdbc.password" value=""/>
</properties>
</persistence-unit>
</persistence>
<property name="eclipselink.jdbc.driver" value=""/>
I'd say that's your problem. You're explicitly specifying no driver. Omit it or use org.postgresql.Driver.

Eclipse RCP throws exception when I try to use JPA for local data storage

I have the following code in my RCP application:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("todos");
EntityManager em = emf.createEntityManager();
Query q = em.createQuery("select t from Todo t");
#SuppressWarnings("unchecked")
List<Todo> todos = (List<Todo>)q.getResultList();
My config is META-INF/persistence.xml and contains:
<?xml version="1.0" encoding="UTF-8" ?>
<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"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="todos" transaction-type="RESOURCE_LOCAL">
<class>foo.bar.Todo</class>
<properties>
<property name="javax.persistence.jdbc.driver"
value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url"
value="jdbc:derby:/home/pocon64/myDb;create=true" />
<property name="javax.persistence.jdbc.user" value="test" />
<property name="javax.persistence.jdbc.password" value="test" />
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
</properties>
</persistence-unit>
</persistence>
When I try to run the application, it starts fine, but displays the error:
Could not create the view:
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: org.eclipse.core.runtime.internal.adaptor.ContextFinder#4b51ac10
Internal Exception: Exception [EclipseLink-30009] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while trying to load persistence unit at url: bundleresource://51.fwk2013125681:10
Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while processing persistence.xml from URL: bundleresource://51.fwk2013125681:10
Internal Exception:
(1. URI was not reported to parser for entity [document])
The db file isn't created at all. Any ideas what's causing this?
ADDITION: Full stack trace below:
Local Exception Stack:
Exception [EclipseLink-30009] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while trying to load persistence unit at url: bundleresource://51.fwk998462082:10
Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while processing persistence.xml from URL: bundleresource://51.fwk998462082:10
Internal Exception:
(1. URI was not reported to parser for entity [document])
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionLoadingFromUrl(PersistenceUnitLoadingException.java:100)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceArchive(PersistenceUnitProcessor.java:538)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.getPersistenceUnits(PersistenceUnitProcessor.java:444)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfoInArchive(JPAInitializer.java:172)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfoInArchives(JPAInitializer.java:154)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfo(JPAInitializer.java:135)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:73)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
at com.diligentgaming.dcm.workstation.plugins.core.dashboard.DashboardView.createPartControl(DashboardView.java:64)
at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:375)
at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:229)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:313)
at org.eclipse.ui.internal.ViewPane.setVisible(ViewPane.java:534)
at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180)
at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270)
at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:473)
at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1245)
at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1198)
at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1597)
at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:643)
at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:570)
at org.eclipse.ui.internal.PartSashContainer.createControl(PartSashContainer.java:568)
at org.eclipse.ui.internal.PerspectiveHelper.activate(PerspectiveHelper.java:272)
at org.eclipse.ui.internal.Perspective.onActivate(Perspective.java:981)
at org.eclipse.ui.internal.WorkbenchPage.onActivate(WorkbenchPage.java:2714)
at org.eclipse.ui.internal.WorkbenchWindow$28.run(WorkbenchWindow.java:3030)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchWindow.setActivePage(WorkbenchWindow.java:3011)
at org.eclipse.ui.internal.WorkbenchWindow.busyOpenPage(WorkbenchWindow.java:799)
at org.eclipse.ui.internal.Workbench$23.runWithException(Workbench.java:1229)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3938)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3615)
at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803)
at org.eclipse.ui.internal.Workbench$33.runWithException(Workbench.java:1600)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3938)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3615)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2609)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at com.diligentgaming.dcm.workstation.plugins.core.Application.start(Application.java:20)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: Exception [EclipseLink-30004] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while processing persistence.xml from URL: bundleresource://51.fwk998462082:10
Internal Exception:
(1. URI was not reported to parser for entity [document])
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionProcessingPersistenceXML(PersistenceUnitLoadingException.java:118)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceXML(PersistenceUnitProcessor.java:587)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceArchive(PersistenceUnitProcessor.java:536)
... 63 more
Caused by:
(1. URI was not reported to parser for entity [document])
at org.eclipse.persistence.internal.jpa.deployment.xml.parser.XMLExceptionHandler.error(XMLExceptionHandler.java:28)
at org.eclipse.persistence.internal.jpa.deployment.xml.parser.XMLExceptionHandler.warning(XMLExceptionHandler.java:23)
at gnu.xml.aelfred2.SAXDriver.warn(SAXDriver.java:935)
at gnu.xml.aelfred2.SAXDriver.startExternalEntity(SAXDriver.java:631)
at gnu.xml.aelfred2.XmlParser.pushURL(XmlParser.java:3358)
at gnu.xml.aelfred2.XmlParser.doParse(XmlParser.java:159)
at gnu.xml.aelfred2.SAXDriver.parse(SAXDriver.java:320)
at gnu.xml.aelfred2.XmlReader.parse(XmlReader.java:294)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceXML(PersistenceUnitProcessor.java:577)
... 64 more</code>
The answer turned out to be to remove the gnujaxp.jar from the Classpath, everything seems to work fine after that.

Categories