I have Vaadin project with JPA 2.1 + EclipseLink + MySQL.
In eclipse in project settings I set connection to base and drivers correctly. Without problem I "generate Entities from Tables", but persistence.xml haven't info about driver, connection, login, pass to DB.
My auto generate 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="RadiologicalWarehouse">
<class>pl.intibs.rw.entitites.Message</class>
<class>pl.intibs.rw.entitites.Part</class>
<class>pl.intibs.rw.entitites.Role</class>
<class>pl.intibs.rw.entitites.Sample</class>
<class>pl.intibs.rw.entitites.SampleHistory</class>
<class>pl.intibs.rw.entitites.User</class>
</persistence-unit>
</persistence>
If I run my application with simple query, I get of course exception:
javax.servlet.ServletException: com.vaadin.server.ServiceException: javax.persistence.PersistenceException: Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:239)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
If JPA has defined the connection in the project, why does not generate this persistence automatically?
Screenshot settings JPA: http://i.imgur.com/T2oEdHA.png
Based on what I understand you have set parameters for the Jpa plugin to eclipse and this is much different to set the parameters to persistence provider. Firstly you have to decide what persitent provide use and specify it in the persistence.xml together with the others paramenters.
This is an example of persistence.xml with eclipseLink:
<persistence>
<persistence-unit name="myUnit">
<provider>yourProvider</provider>
<class>it.myCompany.domain.MyFirstClass</class>
<class>it.myCompany.domain.MySecondClassClass</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="${driverClass}" />
<property name="javax.persistence.jdbc.url" value="${connectionURL}" />
<property name="javax.persistence.jdbc.user" value="${username}" />
<property name="javax.persistence.jdbc.password" value="${password}" />
<property name="eclipselink.logging.level" value="info"/>
</properties>
<shared-cache-mode>NONE</shared-cache-mode>
</persistence-unit>
</persistence>
Related
I'm struggling for a few days about this error.
When I try to deploy from ide(IntelliJ-eclipse), it works correct.
But when I try to deploy from WebLogic console, I got these errors;
Error Unable to access the selected application.
Error Unable to invoke Annotation processoror.
Error Unable to invoke Annotation processoror.
For more information, I checked logs and errors from stack trace.
It looks like the main error is: javax.persistence.PersistenceException: No Persistence provider for EntityManager named.
In debug, throwing from this code; Persistence.createEntityManagerFactory("persistanceUnitName");
Persistence classes are coming from javaee-web-abi-7.0.jar.
Everything looks fine in 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="persistanceUnitName"
transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>dataSource</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.target-database" value="Oracle" />
<property name="eclipselink.logging.parameters" value="true" />
<property name="eclipselink.logging.logger" value="DefaultLogger" />
<property name="eclipselink.logging.level" value="WARNING" />
<property name="eclipselink.refresh" value="true" />
<property name="eclipselink.query-results-cache" value="false" />
<!-- <property name="eclipselink.ddl-generation" value="create-or-extend-tables" />-->
</properties>
</persistence-unit>
</persistence>
persistance.xml located in /WEB-INF/classes/META-INF
We got a case like that: we have a test and prep environment. In test, it works, in prep doesn't work, in local doesn't work (from WebLogic console). Unfortunately, I can't see test server configs. But I expect the same options with prep. Anyway forget other environments, firstly I need to deploy successful from local.
Could you pls help me, I really don't know what I miss. Read every topic, tried everything
It looks like a classpath issue. Check your weblogic classpath.
If you are using eclipselink library must be loaded first when you are deploying.
Check this.
Add eclipselink into your project with scope provided:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.0</version>
<scope>provided<scope>
</dependency>
add same dependency into your weblogic classpath:
$WEBLOGIC_HOME/user_projects/domains/base_domain/lib
Then, add below to your weblogic.xml to use eclipselink library.
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>org.eclipse.persistence.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
This is essentially a duplicate of How to locate the source of JBAS011470 error in JBoss?
But essentially, As soon as I add a second persistence unit, it gives me this error. It's ridiculous. I'm not going to disable the JPA subsystem like some people suggest - that sounds wrong.
My persistence.xml setup is as follows, where java:/NAME is set up as a datasource in standalone.xml:
<?xml version="1.0"?>
<persistence 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"
version="2.0">
<persistence-unit name="name" transaction-type="JTA">
<jta-data-source>java:/NAME</jta-data-source>
<class>za.co.classes.A</class>
<class>za.co.classes.B</class>
<class>za.co.classes.C</class>
<properties>
<property name="hibernate.transaction.jta.platform"
value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
<property name="jboss.entity.manager.factory.jndi.name"
value="java:jboss/persistence/NAME" />
<property name="jboss.entity.manager.jndi.name"
value="java:jboss/persistence/em/NAME" />
<property name="hibernate.dialect" value="za.co.equrahealth.dao.SQLServerDialect" />
</properties>
</persistence-unit>
The error starts as soon as I add a second persistence unit. So spring context is irrelevant.
Well, I luckily have multiple databases within the same schema, so I came up with a workaround. But it's obviously not going to solve the problem when there are multiple schemas. I think the cause of this issue might actually be a bug in JBoss.
#PersistenceContext
private EntityManager entityManager;
private EntityManager getEntityManager(String source)
{
if ("a".equalsIgnoreCase(source))
{
entityManager.createNativeQuery("USE A_DB;").executeUpdate();
}
else
{
entityManager.createNativeQuery("USE B_DB").executeUpdate();
}
return entityManager;
}
I have set up a project in Netbeans, created a script, made a new database with javadb. I can connect to it by gui - display the tables contents etc, but when i run an application with:
EntityManager em = Persistence.createEntityManagerFactory("lab5PU").createEntityManager();
i get this quite long exception:
[EL Info]: 2013-04-05 21:40:45.554--ServerSession(1198260109)--EclipseLink, version: Eclipse Persistence Services - 2.3.0.v20110604-r9504
[EL Severe]: 2013-04-05 21:40:45.574--ServerSession(1198260109)--Local Exception Stack:
Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Exception in thread "AWT-EventQueue-0" javax.persistence.PersistenceException: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [org.apache.derby.jdbc.ClientDriver] not found.
Exception Description: Configuration error. Class [org.apache.derby.jdbc.ClientDriver] not found.
at org.eclipse.persistence.exceptions.DatabaseException.configurationErrorClassNotFound(DatabaseException.java:82)
I can see the javadb drivers in the driver section in services, so i have no idea what the error might be.
EDIT: persistance.xml as requested:
<?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="lab5PU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>lab5.Colleagues</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/lab5"/>
<property name="javax.persistence.jdbc.password" value="mypass"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.user" value="admin"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
I think the problem you have is that you don't have the Derby driver in the classpath of the project.
You can easily achieve that adding the JavaDB library to your project:
Right-click on the project
Properties -> Libraries
Add Library -> JavaDB driver
This includes derby.jar, derbyclient.jar and derbynet.jar in your project's classpath.
The derbyclient.jar contains the class org.apache.derby.jdbc.ClientDriver your code is complaining about.
I know there are some other questions on this subject, but none of the answers worked.
I am new to JPA and I am using EclipseLink as implementation and Eclipse as IDE.
This is my persistence.xml (it is in META-INF folder):
<?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="DBService" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.maze.model.EventModel</class>
<class>com.maze.model.StoryModel</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/mazedb;create=true" />
<property name="javax.persistence.jdbc.user" value="user" />
<property name="javax.persistence.jdbc.password" value="pass" />
<!-- 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>
and here I am trying to get an EntityManagerFactory
private EntityManagerFactory emf;
emf = Persistence.createEntityManagerFactory("DBService");
At runtime, I get this error:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named DBService
I have followed the steps from tutorials, but no results...
Edit: I have also added into WEB-INF/lib these jars: eclipselink.jar; javax.persistence_2.0.3.v201010191057.jar; mysql-connector-java-5.1.17-bin.jar, added JPA to the Project Facets but no have seen no results yet...
put your persistence.xml in the META-INF directory of your war file. Also, put a copy in your lib directory and the classes directory.
I am using eclipselink at work, using a standalone jar package that contains my entity classes, a MET-INF directory with the persistence.xml and it works fine.
Probably you need to make a jar file containing the entity classes, plus a MET-INF/persistence.xml, and add this jar file to your lib directory, alongside the eclipselink.jar.
The other thing to check is the RESOURCE-LOCAL, you should use this if you are using JPA in a web-app, with no entity beans components, or in a standalone application.
You must put your persistence.xml in the META-INF and write persistence.xml with Lowercase letter.
I think you wrote first letter or some letter with Capital letter and i have this error too.
You must write exactly like this: persistence.xml
I am newbie with JPA. I'm trying to run some sample code using JPA but I get the following exception:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named MyJPAApplicationPU
I put my exception message here,
INFO: Could not find any META-INF/persistence.xml file in the classpath
javax.persistence.PersistenceException: No Persistence provider for EntityManager named MyJPAApplicationPU
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at com.myJpa.TestJPA.setUp(TestJPA.java:30)
at com.myJpa.TestJPA.main(TestJPA.java:72)
Any help would be appreciated.
Well, the error is self explaining, you need to provide a META-INF/persistence.xml to use JPA. This file is used to define a "persistence unit". From the JPA 1.0 specification:
6.2.1 persistence.xml file
A persistence.xml file defines a
persistence unit. It may be used to
specify managed persistence classes
included in the persistence unit,
object/relational mapping information
for those classes, and other
configuration information for the
persistence unit and for the entity
manager(s) and entity manager factory
for the persistence unit. The
persistence.xml file is located in
the META-INF directory of the root
of the persistence unit. This
information may be defined by
containment or by reference, as
described below.
Here is a sample persistence.xml for a Java SE environment (using Hibernate as JPA provider):
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd"
version="1.0">
<persistence-unit name="MyJPAApplicationPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.mycompany.Foo</class>
<class>com.mycompany.Bar</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.DriverManagerConnectionProvider" />
<property name="hibernate.connection.url" value="jdbc:hsqldb:mem:unit-testing-jpa"/>
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
Some comments about the above file:
when running in a Java SE environment, you cannot rely on JTA and the transaction type must be RESOURCE_LOCAL (which is actually the default in a Java SE environment but specifying it make it more clear).
when running in a Java SE environment, you cannot use a JDNI data source and the provider will obtain connections directly from the JDBC driver so you must pass the relevant informations to the provider (driver class name, connection url, user, password). With JPA 1.0 the properties used to pass these metadata are provider specific.
To insure the portability of a Java SE application, it is necessary to explicitly list the managed persistence classes that are included in the persistence unit.
For JPA to work, you need META-INF/persistence.xml. I will assume this is a web-app, so this folder has to be in WEB-INF/classes/.
The persistence.xml file would look like this:
<persistence 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_1_0.xsd"
version="1.0">
<persistence-unit name="MyJPAApplicationPU" transaction-type="RESOURCE_LOCAL">
</persistence-unit>
</persistence>
EntityManagerFactory emf = Persistence.createEntityManagerFactory("<JDBC connection>");
Check the correct JDBC Connection.