1

I am configuring from scratch a new project using Gradle:

apply plugin: 'java-library'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.hsqldb:hsqldb:2.3.4'
    compile 'javax.persistence:persistence-api:1.0.2'
    compile 'org.hibernate:hibernate-core:5.2.8.Final'
    compile 'org.hibernate:hibernate-entitymanager:5.2.8.Final'

    api 'org.apache.commons:commons-math3:3.6.1'

    implementation 'com.google.guava:guava:20.0'

    testImplementation 'junit:junit:4.12'
}

and my persistence.xml (located at src/main/resources/META-INF) 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="app" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>com.fsa.hibernate.model.User</class>


        <properties>
            <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:testdb" />
            <property name="javax.persistence.jdbc.user" value="sa" />
            <property name="javax.persistence.jdbc.password" value="" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
        </properties>
    </persistence-unit>

</persistence>

And I am getting a hard problem to solve:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named app:  The following providers:
org.hibernate.jpa.HibernatePersistenceProvider
Returned null to createEntityManagerFactory.

    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:154)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
    at com.fsa.hibernate.model.UserTest.main(UserTest.java:15)

And that is all the content in the stack trace.

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

2

I believe you are trying to use:

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

but this class is not on your classpath.

As you are using Hibernate, try switching to:

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
MartinTeeVarga
  • 10,478
  • 12
  • 61
  • 98
  • Thanks for your answer. But I have tried this before. after some debbuging here <> , I found that this is the problem: line 110: emf = provider.createEntityManagerFactory(persistenceUnitName, properties); I am getting null at this point... – Filipe Andrade Mar 14 '17 at 02:40
  • 1
    That is a different problem. @sm4's answer is correct for the problem you reported. You can also remove the `javax.persistence:persistence-api` and `org.hibernate:hibernate-entitymanager` dependencies, because the first one comes with `org.hibernate:core` and the second one since 5.2 is a dummy package that just requires core. – coladict Mar 14 '17 at 12:09
  • @coladict thank a lot!!! You and sm4 saved my life big time! My problem is solved now! – Filipe Andrade Mar 14 '17 at 12:43
  • @FilipeAndrade If your problem is solved, would you mind posting your answer or editing mine with what else helped? – MartinTeeVarga Mar 21 '17 at 09:49