1

I'm trying to run a sample JPA based project. I get the error from the title all the time.

I looked here: No Persistence provider for EntityManager named

but found no working solution there.

Here is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>~path.example</groupId>
    <artifactId>example</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>ejb3-persistence</artifactId>
            <version>3.3.2.Beta1</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.9.Final</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jst.server.generic</groupId>
            <artifactId>oc4j</artifactId>
            <version>1.5.105-v200709061325</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.2.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.common</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>4.0.1.Final</version>
            <classifier>tests</classifier>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.4</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>3.1.0.CR2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.4</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-6.0</artifactId>
            <version>1.0.0.Final</version>
            <type>provided</type>
            <scope>pom</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-6.0</artifactId>
            <version>1.0.0.Final</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.container</groupId>
            <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
            <version>1.0.0.CR3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.weld</groupId>
            <artifactId>weld-core</artifactId>
            <version>1.1.5.Final</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.6.4</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.arquillian</groupId>
                <artifactId>arquillian-bom</artifactId>
                <version>1.1.8.Final</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>

It's possible that I have some dependencies that I don't need. As I'm inexperienced I must honestly admit, I was quite desperate and looked for any possible answer, and during that process I added some dependencies that may not be used at all.

Here is the class supposed to make the EntityManager

package ~path.examples.service;

import ~path.examples.testjpa.domain.Person;

import javax.persistence.*;

/**
 * Created by ME on 2015-04-22.
 */
public class JpaTest {
    public static void main(String args[]) {
        EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("jpaTest");
        EntityManager em = entityManagerFactory.createEntityManager();
        EntityTransaction userTransaction = em.getTransaction();

        userTransaction.begin();
        Person person = new Person();
        person.setFirstName("Charles");
        person.setSurname("Dickens");
        em.persist(person);
        userTransaction.commit();
        em.close();
        entityManagerFactory.close();
    }
}

Also:

  1. Im pretty sure that all the files are in the appropriate locations, I also had some problems with me, but I seem to have eliminated that problem (other errors pop out than before) :)

  2. It's probably something obvious that I'm missing, thanks in advance for any help!

edit: It's very likely that the problem lies in persistance.xml file, so here it is (thanks for pointing it out). The location of the file is src/main/resources/META-INF

<?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="JpaTest" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>~path.examples.testjpa.domain.Person</class>
        <properties>
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
        </properties>

    </persistence-unit>
</persistence>
Community
  • 1
  • 1
Jan Ossowski
  • 328
  • 1
  • 2
  • 18
  • 1
    have you a persistence.xml file ? – Vyncent Apr 23 '15 at 09:37
  • And assuming yes: WHERE is it? "i'm pretty sure" is not a reason to hide the details as the option that you made a mistake is still very much there. You say so yourself. – Gimby Apr 23 '15 at 09:56
  • Yes, of course I have it, and I intended to post it. Edited, thanks for pointing out, simply forgot :) By the way, the location is correct almost for sure (I must admit I experimented a little, and in any other location it wouldn't even be detected) but it's very likely that there is a mistake inside the file, that I dont see. – Jan Ossowski Apr 23 '15 at 10:27

2 Answers2

1

Maybe you didn't add Hibernate jars to the project classpath? Missing provider jars (in this case Hibernate) will not show you compile errors, as they are required during the runtime.

Szarpul
  • 1,531
  • 11
  • 21
0

You need to change:

<provider>org.hibernate.ejb.HibernatePersistence</provider>

to:

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
  • 1
    I'm sorry to say that, but apparently You are wrong. I just eliminated the error by changing to ((obviously simple spelling mistake)) which eliminated the previous error, but made a new error "The application must supply JDBC connections" in line userTransaction.begin(); When I tried doing what You said, it took me a step back to the previous error :) thanks for trying though, i will now appreciate help with the new one – Jan Ossowski Apr 23 '15 at 10:56
  • Is it? [How about this](http://stackoverflow.com/questions/22691252/error-deprecated-persistenceprovider-use-hibernatepersistenceprovider-instead)? – Vlad Mihalcea Apr 23 '15 at 10:57
  • I am far from trying to depreciate Your help, as it is very welcome, and obviously You know much more about the topic than I do. I'm just saying what happens. Doing what You suggested takes me a step back, to the error that I just eliminated by correcting the spelling mistake. – Jan Ossowski Apr 23 '15 at 11:19
  • The old class is deprecated and it could be removed in a future version. I'll keep the answer as it might help somebody else. – Vlad Mihalcea Apr 23 '15 at 11:25
  • Since I'm getting a new error, should I make a new topic, or just wait for a new answer here? – Jan Ossowski Apr 23 '15 at 11:46
  • I think you should provide an answer to this question and accept it, and ask a new question for whatever 's left. – Vlad Mihalcea Apr 23 '15 at 11:53