Home No persistence provider
Reply: 1

No persistence provider

Sindico Published in 2017-10-22 15:22:35Z

I am trying to run a very basic JPA example on Wildfly. This is the structure of my project:

Person and Project are two JPA entities. This is the content of 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="testJpa">

         <property name="eclipselink.target-database" value="Derby"/>  
         <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/JPADB"/>
         <property name="javax.persistence.jdbc.user" value="user"/>
         <property name="javax.persistence.jdbc.password" value="pwd"/>
         <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
         <property name="eclipselink.logging.level" value="FINE"/>
         <property name="eclipselink.ddl-generation" value="create-tables"/>


Tables are correctly generated from the entity classes so I know the persistence.xml is valid.

I am trying to create an entity in the CreatePerson class, like this:

public class CreatePerson {

   public static void main( String[ ] args ) {

      EntityManagerFactory emfactory = Persistence.createEntityManagerFactory("testJpa");

      EntityManager entitymanager = emfactory.createEntityManager( );
      entitymanager.getTransaction( ).begin( );

      Person usr = new Person( ); 

      entitymanager.persist( usr );
      entitymanager.getTransaction( ).commit( );

      entitymanager.close( );
      emfactory.close( );

I get the following error

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named testJpa
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
    at services.CreatePerson.main(CreatePerson.java:11)
Oleg Gritsak
Oleg Gritsak Reply to 2017-10-23 08:56:51Z

It is totally unclear what are you doing. Wildfly is an JavaEE application server, but I see JavaSE class public static void main.

You should create JavaEE project (for Eclipse, as far as I know you need to download Eclipse IDE for Java EE Developers ) then probably create DAO EJB, inject EntityManager in it with

@PersistenceContext(unitName = "puName")
private EntityManager em;

then you code should work

Person usr = new Person("blabla"); 

IMHO, you should look for another tutorial.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312346 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO