RCP e4 EclipseLink Error: No Persistence provider for EntityManager named - eclipselink

I am trying to apply a persistence framework to an eclipse rcp e4 application. For this purpose, I created an example of a feature project, almost following the tutorial https://www.vogella.com/tutorials/JavaPersistenceAPI/article.html, but adapting for rcp. However I got the error "Persistence provider for EntityManager named xxx not found". I have searched for a week but found no solution. Could someone please tell me, what the error really is and how to resolve it?
The persistence.xml is located in project tasks.model folder META-INF. The eclipse.jar and javax.persistence.jar are in another plugin project (Earlier I defined maven dependencies in pom.xml. Although eclipse reports no compilation errors, but running rcp product would result in an error that ClassDefNotFoundException for persistence, so putting javax.persistence.jar in a separate plugin removed this error). Some answers suggested that the persistence.xml should be in the folder src/resources/META-INF. But in a plugin project the folder META-INF is already in its default place. I even created an extra folder resources/META-INF and put the persistence.xml in that, but it did not help. If I created a normal maven project, then things work properly, also when I change the database to mysql in localhost. The errors appear when I convert the project into a plugin project for building rcp applications.
The error "No Persistence provider for EntityManager" occurs when I invoke the command:
factory = Persistence.createEntityManagerFactory("todos");
My persistence.xml file looks like:
<?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">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>tasks.model.Todo</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:/tempGeo/simpleDB" />
<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>

Related

In IntelliJ 2016.2 Ultimate edition, how to add JPA facet when we don't use a persistence.xml?

My Project doesnot have a persistence.xml.
I use annotations in my spring-boot based application.
How can I add the JPA facet ?
When I try to add a jpa facet, it enforces me to select persistence.xml, and if it is not present, it is trying to create one, which I don't want.
Can anyone help me with this?
For now I got this working with a near-empty persistence.xml in the META-INF folder of my project.
After this it works fine, but I would love this to work without this persistence.xml as well.
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1">
<persistence-unit name="myPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<properties>
<!– Scan for annotated classes and Hibernate mapping XML files –>
<property name="hibernate.archive.autodetection" value="class" />
</properties>
</persistence-unit>
</persistence>
If anybody knows any other solution please comment.
else if this works for you, you can rate this answer up :-)

Apply play framework evolution in test Environment

I am set up my play framework jpa as following:
in application.conf:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
db.default.user=sa
db.default.password=""
applyEvolutions.default=true
db.default.jndiName=DefaultDS
jpa.default=defaultPersistenceUnit
persistence.xml:
<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="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
I am start play in test as this:
start(fakeApplication(inMemoryDatabase(), globalSettings));
running this project working well but testing it fails because of lacking database evolution!
How can I enable Play Framework evolution in test environment?
I am using hibernate 3.6
Force down evolutions too in your application.conf :
applyDownEvolutions.default=true
Be careful, if you use the same conf file in production.
Try to set hibernate.hbm2ddl.auto to "none" and hence your evolutions should apply correctly.
I guess hibernate "assumes control" before the evolution plugin and that causes problem. You may try to modify plugin loading order (JPAPlugin vs EvolutionPlugin) to see if it makes any difference.

java persistence collection of metamodel types is empty

While deploying my jpa project to wildfly server i am gettings following warning:
The collection of metamodel types is empty.
Model classes may not have been found during entity
search for Java SE and some Java EE container managed persistence units.
Please verify that your entity classes are referenced in persistence.xml using
either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
My persistence xml looks like this
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1">
<persistence-unit name="primary" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/example</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="javax.persistence.schema-generation.create-source" value="metadata"/>
<property name="javax.persistence.schema-generation.drop-source" value="metadata"/>
<property name="eclipselink.target-server" value="JBoss"/>
<property name="eclipselink.weaving" value="static"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/example"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="xxx"/>
</properties>
</persistence-unit>
</persistence>
My Database tables are not created due to this.
Please help me understand this problem. As i am not able to understand the root cause of this.
For people who would come across this question like I did: I've just met this issue in Eclipse 2020-06 when running JPA Tools > Generate Tables from Entities, which is a situation probably different from the one in the question albeit with a strictly identical error message.
It turns out that the only thing needed to work around it is to hit Project > Clean and select the JPA project in the list.
For some unknown reason in my case, cleaning the project is necessary between runs of the Generate Tables command. I can't figure out why but that's the way it is. HTH

How to externalize properties of persistence.xml for JBOSS 7.1.1?

My persistence.xml is currently present in the application war(in META-INF folder.). However, for the application to be run across multiple DBs the persistence needs to be changed again and again. I want to avoid it. But, I am not able to understand how will i configure the properties(like dialect) in the persistence.xml from, say, a property file which i would change based on my DB, hence not compelling me to update and redeploy my war.
My problem can also be resolved if i can configure the dialect in the datasource in standalone.xml where i have mentioned other DB details. I am not being able to make out what the property would be.
Though i would prefer a solution for the first one.
PS: I am rookie in Web App development. Questions might annoy you. :D
I use a method that works well for hibernate.
1) put the hibernate configuration properties in a xml file (call it hibernate.cfg.xml but it's not mandatory)
this is an example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.search.default.directory_provider">ram</property>
</session-factory>
</hibernate-configuration>
you can put there only hibernate properties that do not start with hibernate.ejb
2) Create a jboss module. It's very simple. Suppose you want to call the module com.myorganization.config than create a directory structure in the modules folder of you server installation: /com/myorganization/config/main. In the main folder put the hibernate.cfg.xml file and the following module.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.myorganization.config">
<resources>
<resource-root path="."/>
</resources>
</module>
3) In your persistence.xml adding the following property:
<property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml" />
4) Finally, in the META-INF/MANIFEST.MF file add the following line:
Dependencies: com.myorganization.config
If you like maven use the maven-war-plugin in order to change the MANIFEST.MF:
<configuration>
<archive>
<manifestEntries>
<Dependencies>com.myorganization.config</Dependencies>
</manifestEntries>
</archive>
</configuration>
That's all.

Migration from glassfish to apache

I created a project using Netbeans and selected Glassfish 3.1 as a server, it also uses Derby database. Now I want to migrate to Apache Tomcat 7, I just did the following:
Stopped Glassfish
Changed the Netbeans project's properties to use Apache 7 instead of Glassfish
Added Apache to Netbeans and started it
When I try to build the project, several error messages appear like:
error: cannot find symbol
import javax.persistence.Basic;
although I ensured that /bin path of Java is set correctly in Apache server properties in Netbeans and that src.zip path is also set.
I think there are some steps that must be followed to have a successful migration, can any one guide me?
Thanks
Apache Tomcat does not come with the JPA specification. It is a Servlet container only.
You must add JPA specification plus Hibernate (implementation) to your project and make sure it will be deployed on your WEB-INF/lib.
Then, make sure your Persistence Unit is of transaction-type="RESOURCE_LOCAL", and configure all necessary properties to create a connection.
Example:
<persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL">
<class>com.sample.domain.YourEntity</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:." />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>
Obs: this is an HSQLDB example. Adjust for Derby. ;-)
UPDATE: there's a great tutorial for Tomcat+JPA+EclipseLink here.