No Persistence provider for EntityManager named
Asked Answered
F

33

173

I have my persistence.xml with the same name using TopLink under the META-INF directory. Then, I have my code calling it with:

EntityManagerFactory emfdb = Persistence.createEntityManagerFactory("agisdb");

Yet, I got the following error message:

2009-07-21 09:22:41,018 [main] ERROR - No Persistence provider for EntityManager named agisdb
javax.persistence.PersistenceException: No Persistence provider for EntityManager named agisdb
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)

Here is the persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
    <persistence-unit name="agisdb">
        <class>com.agis.livedb.domain.AddressEntity</class>
        <class>com.agis.livedb.domain.TrafficCameraEntity</class>
        <class>com.agis.livedb.domain.TrafficPhotoEntity</class>
        <class>com.agis.livedb.domain.TrafficReportEntity</class>
        <properties>
            <property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/agisdb"/>
            <property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="toplink.jdbc.user" value="root"/>
            <property name="toplink.jdbc.password" value="password"/>
        </properties>
    </persistence-unit>
</persistence>

It should have been in the classpath. Yet, I got the above error.

Ferryman answered 21/7, 2009 at 9:29 Comment(0)
M
89

After <persistence-unit name="agisdb">, define the persistence provider name:

<provider>org.hibernate.ejb.HibernatePersistence</provider>
Marotta answered 16/8, 2009 at 21:55 Comment(6)
I am using Derby and it wasn't necessary to specify this (I did, but then removed it once I solved the problem, just to make sure). I was getting the error finally because persistence.xml was not in the src/META-INF folder, even though it had been in a folder in the Eclipse source path for the project. I'm thinking somewhere it's hard-wired to be on src/*Daube
this was not necessary in my case, but classpathing hibernate-entitymanager*.jar as stated in Ualter Jrs answer below. I am using a standalone GWT app with hibernate-core-4.3.7.jar, hibernate-entitymanager-4.3.7.Final.jar and hibernate-jpa-2.1-api-1.0.0.jar.Azzieb
Same with @AndreasDietrich, after replacing "hibernate-core-4.3.10" artifact with "hibernate-entitymanager-4.3.10" in pom.xml (I use maven), this error is gone. Actually, hibernate.org/orm/downloads says that you should use "hibernate-entitymanager-4.3.10" for JPA.Arpent
Apart from this, I also had to move up from hibernate-entitymanager-3.4.0.GA to 3.6.10.Final. Just in case you still have a legacy codebase using Hibernate 3.Sheley
I'm a bit suprised you don't run into a problem with your <provider/>, while using hibernate-4 you should change your provider to <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>, see #23042464 .Thracian
It's also possible that your maven project isn't generating the classpath in Manifest.mf. Check the contents of this file in your generated war.Inclinable
B
91

Put the "hibernate-entitymanager.jar" in the classpath of application.
For newer versions, you should use "hibernate-core.jar" instead of the deprecated hibernate-entitymanager

If you are running through some IDE, like Eclipse: Project Properties -> Java Build Path -> Libraries.

Otherwise put it in the /lib of your application.

Beal answered 25/2, 2011 at 18:36 Comment(7)
Took me a few hours to figure this was the cause. For other people searching for this bloody jar, in case of Hibernate 4.1.3, its in hibernate-release-4.1.3.Final\lib\jpa\hibernate-entitymanager-4.1.3.Final.jarScull
And for those of us who are using Maven, that would be groupid org.hibernate artifactid hibernate-entitymanagerCapriole
It's been eclipselink.jar for me, which was missing in the path. No hibernate*something.jar in the path at all.Remus
Just spent a few hours confirming persistence.xml was on class path, and comparing every facet of a project this worked for and a project it didn't work for. Very misleading error message since it can happen if persistence.xml is missing, if the PU with that name is missing, or apparently if a hibernate jar is missing!Television
For me it was org.eclipse.persistence.jpa with scope test.Bagwell
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>4.3.0.Final</version> </dependency>Husband
"For newer versions, you should use hibernate-core.jar instead of the deprecated hibernate-entitymanager" - THANK YOU. I tried a bunch before this worked for me. Is this documented somewhere besides stackoverflow?Voter
M
89

After <persistence-unit name="agisdb">, define the persistence provider name:

<provider>org.hibernate.ejb.HibernatePersistence</provider>
Marotta answered 16/8, 2009 at 21:55 Comment(6)
I am using Derby and it wasn't necessary to specify this (I did, but then removed it once I solved the problem, just to make sure). I was getting the error finally because persistence.xml was not in the src/META-INF folder, even though it had been in a folder in the Eclipse source path for the project. I'm thinking somewhere it's hard-wired to be on src/*Daube
this was not necessary in my case, but classpathing hibernate-entitymanager*.jar as stated in Ualter Jrs answer below. I am using a standalone GWT app with hibernate-core-4.3.7.jar, hibernate-entitymanager-4.3.7.Final.jar and hibernate-jpa-2.1-api-1.0.0.jar.Azzieb
Same with @AndreasDietrich, after replacing "hibernate-core-4.3.10" artifact with "hibernate-entitymanager-4.3.10" in pom.xml (I use maven), this error is gone. Actually, hibernate.org/orm/downloads says that you should use "hibernate-entitymanager-4.3.10" for JPA.Arpent
Apart from this, I also had to move up from hibernate-entitymanager-3.4.0.GA to 3.6.10.Final. Just in case you still have a legacy codebase using Hibernate 3.Sheley
I'm a bit suprised you don't run into a problem with your <provider/>, while using hibernate-4 you should change your provider to <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>, see #23042464 .Thracian
It's also possible that your maven project isn't generating the classpath in Manifest.mf. Check the contents of this file in your generated war.Inclinable
N
70

Make sure that the persistence.xml file is in the directory: <webroot>/WEB-INF/classes/META-INF

Nosedive answered 6/12, 2009 at 20:29 Comment(4)
this didn't work for me, brought the Persistence unit not found: 'null' error. Moving it back to /src/main/resources/META-INF/persistence.xmlDaggett
I guess this applies for those who's using toplink (or other web-related stuff), for everyone else other answers here may be more appropriate.Capriole
Thanks, for me the path is target/classes/META-INFGraminivorous
Same, for some weird reason it needs to be in a META-INF directory, otherwise won't work...Nalchik
O
22

Faced the same issue and couldn't find solution for quite a long time. In my case it helped to replace

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

with

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

Took solution from here

Orabelle answered 13/4, 2017 at 15:40 Comment(1)
Was upgrading from Hibernate 4.3.5 to 5.2.12 and this provider name change fixed the problem for me. That setting appears to allow JPA to use the core .jar file instead of the entity-manger .jar that shows as deprecated on the Maven central repository. Thanks so much for sharing.Wiseman
N
19

I needed this in my pom.xml file:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.2.6.Final</version>
</dependency>
Nawab answered 20/10, 2013 at 2:55 Comment(2)
Works for version 4.3.11.Urethrectomy
It's deprecated, see above. Use hibernate-core instead.Afterburner
M
10

There is another point: If you face this problem within an Eclipse RCP environment, you might have to change the Factory generation from Persistence.createEntityManagerFactory to new PersistenceProvider().createEntityManagerFactory

see ECF for a detailed discussion on this.

Motel answered 24/8, 2011 at 12:16 Comment(2)
This was the exact problem I was having with org.eclipse.persistence.jpa 2.4.0. I literally spent 2 hours pulling my hair out wondering why it couldn't find my persisence.xml. All the examples do not seem to incorporate this. oh well ... many many thanks!Welldressed
'PersistenceProvider' is abstract; cannot be instantiatedBlemish
B
9

Maybe you defined one provider like <provider>org.hibernate.ejb.HibernatePersistence</provider> but referencing another one in jar. That happened with me: my persistence.xml provider was openjpa but I was using eclipselink in my classpath. Hope this help!

Bitterweed answered 13/5, 2010 at 20:33 Comment(0)
T
6

Quick advice:

  • check if persistence.xml is in your classpath
  • check if hibernate provider is in your classpath

With using JPA in standalone application (outside of JavaEE), a persistence provider needs to be specified somewhere. This can be done in two ways that I know of:

In my case, I found out that due to maven misconfiguration, hibernate-entitymanager jar was not included as a dependency, even if it was a transient dependency of other module.

Thao answered 6/3, 2014 at 10:15 Comment(1)
/facepalm - I forgot to add the maven dependency for the hibernate provider. Thank you!Hewart
C
5

If you are using Eclipse make sure that exclusion pattern does not remove your persistence.xml from source folders on build path.

  1. Go to Properties -> Java Build Path -> Source tab
  2. Check your exclusion pattern which is located at
    MyProject/src/main/java -> Excluded: <your_pattern>
    tree node
  3. Optionally, set it to Excluded: (None) by selecting the node and clicking Edit... button on the left.
Cassidycassie answered 6/9, 2013 at 15:5 Comment(1)
Solved my problem. Excluded pattern was set to "**" after a fetch/pull. I don't know why...Inseparable
P
5

I'm some years late to the party here but I hit the same exception while trying to get Hibernate 3.5.1 working with HSQLDB and a desktop JavaFX program. I got it to work with the help of this thread and a lot of trial and error. It seems you get this error for a whole variety of problems:

No Persistence provider for EntityManager named mick

I tried building the hibernate tutorial examples but because I was using Java 10 I wasn't able to get them to build and run easily. I gave up on that, not really wanting to waste time fixing its problems. Setting up a module-info.java file (Jigsaw) is another hairball many people haven't discovered yet.

Somewhat confusing is that these (below) were the only two files I needed in my build.gradle file. The Hibernate documentation isn't clear about exactly which Jars you need to include. Entity-manager was causing confusion and is no longer required in the latest Hibernate version, and neither is javax.persistence-api. Note, I'm using Java 10 here so I had to include the jaxb-api, to get around some xml-bind errors, as well as add an entry for the java persistence module in my module-info.java file.

Build.gradle

// https://mvnrepository.com/artifact/org.hibernate/hibernate-core
compile('org.hibernate:hibernate-core:5.3.1.Final')

// https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'

Module-info.java

// Used for HsqlDB - add the hibernate-core jar to build.gradle too
requires java.persistence;

With hibernate 5.3.1 you don't need to specify the provider, below, in your persistence.xml file. If one is not provided the Hibernate provider is chosen by default.

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

The persistence.xml file should be located in the correct directory so:

src/main/resources/META-INF/persistence.xml

Stepping through the hibernate source code in the Intellij debugger, where it checks for a dialect, also threw the exact same exception, because of a missing dialect property in the persistence.xml file. I added this (add the correct one for your DB type):

<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>

I still got the same exception after this, so stepping through the debugger again in Intellij revealed the test entity I was trying to persist (simple parent-child example) had missing annotations for the OneToMany, ManyToOne relationships. I fixed this and the exception went away and my entities were persisted ok.

Here's my full final persistence.xml:

<persistence 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"
         version="2.1">

<persistence-unit name="mick" transaction-type="RESOURCE_LOCAL">
    <description>
        Persistence unit for the JPA tutorial of the Hibernate Getting Started Guide
    </description>

    <!-- Provided in latest release of hibernate
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    -->

    <class>com.micks.scenebuilderdemo.database.Parent</class>
    <class>com.micks.scenebuilderdemo.database.Child</class>

    <properties>
        <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbc.JDBCDriver"/>

        <property name="javax.persistence.jdbc.url"
                  value="jdbc:hsqldb:file:./database/database;DB_CLOSE_DELAY=-1;MVCC=TRUE"/>

        <property name="javax.persistence.jdbc.user" value="sa"/>
        <property name="javax.persistence.jdbc.password" value=""/>

        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.hbm2ddl.auto" value="create"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
    </properties>

</persistence-unit>

</persistence>

I probably wasted about half a day on this gem. My advice would be to start very simple - a single test entity with one or two fields, as it seems like this exception can have many causes.

Precinct answered 24/6, 2018 at 15:31 Comment(1)
Thanks a ton for the configuration details Really helped resolving it.Thus
D
4

Corner case: if you are using m2Eclipse, it automatically puts in excludes on your resources folders. Then when you try to run tests inside eclipse, the subsequent absence of persistence.xml will produce this error.

Dotation answered 25/6, 2010 at 17:26 Comment(0)
R
3

Make sure you have created persistence.xml file under the 'src' folder. I created under the project folder and that was my problem.

Ride answered 27/11, 2011 at 3:59 Comment(1)
Eclipse 4.4.0 doesn't want to nest SRC folders, so I was putting META-INF at the top level, thinking persistence.xml being on the classpath would be adequate. NOT! I had to create manually a src/META-INF (in the operating system) and move the persistence.xml file by hand. Perhaps it's possible to do this in Eclipse, but I couldn't figure it out.Daube
S
3

If you're using Maven, it could be that it is not looking at the right place for the META-INF folder. Others have mentioned copying the folder, but another way that worked for me was to tell Maven where to look for it, using the <resources> tag. See: http://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.html

Scatter answered 15/12, 2016 at 8:32 Comment(0)
I
2

It happenes when the entity manager is trying to point to many persistence units. Do the following steps:

  1. open the related file in your editor (provided your project has been closed in your IDE)
  2. delete all the persistence and entity manager related code
  3. save the file
  4. open the project in your IDE
  5. now bind the db or table of your choice
Ist answered 23/8, 2010 at 14:32 Comment(0)
O
2

I faced the same problem, but on EclipseLink version 2.5.0.

I solved my problem by adding yet another jar file which was necessarily (javax.persistence_2.1.0.v201304241213.jar.jar);

Jars needed:
- javax.persistence_2.1.0.v201304241213.jar
- eclipselink.jar
- jdbc.jar (depending on the database used).

I hope this helps.

Orelee answered 13/4, 2014 at 11:31 Comment(0)
R
2

I also had this error but the issue was the namespace uri in the persistence.xml.

I replaced http://xmlns.jcp.org/xml/ns/persistence to http://java.sun.com/xml/ns/persistence and the version 2.1 to 2.0.

It's now working.

Runyon answered 25/4, 2014 at 8:30 Comment(1)
That's exactly what happened for me using Tomcat.. I just added a full header to clarify for new usersHaiduk
S
2

You need to add the hibernate-entitymanager-x.jar in the classpath.

In Hibernate 4.x, if the jar is present, then no need to add the org.hibernate.ejb.HibernatePersistence in persistence.xml file.

Spoony answered 25/5, 2014 at 19:36 Comment(0)
C
2

In my case, previously I use idea to generate entity by database schema, and the persistence.xml is automatically generated in src/main/java/META-INF,and according to https://mcmap.net/q/144721/-maven-eclipse-could-not-find-any-meta-inf-persistence-xml-file-in-the-classpath, I move it to src/main/resources/META-INF, also marked META-INF as source root. It works for me.

But just simply marking original META-INF(that is, src/main/java/META-INF) as source root, doesn't work, which confuses me.

and this is the structre: enter image description here

Candor answered 25/11, 2019 at 7:34 Comment(1)
This was my solution too. I have a maven project and i created manually this folder (META-INF) under resources. Then i made sure that in war file META-INF folder was placed under: \WEB-INF\classes\META-INFPotbelly
I
1

The question has been answered already, but just wanted to post a tip that was holding me up. This exception was being thrown after previous errors. I was getting this:

property toplink.platform.class.name is deprecated, property toplink.target-database should be used instead.

Even though I had changed the persistence.xml to include the new property name:

<property name="toplink.target-database" value="oracle.toplink.platform.database.oracle.Oracle10Platform"/>

Following the message about the deprecated property name I was getting the same PersistenceException like above and a whole other string of exceptions. My tip: make sure to check the beginning of the exception sausage.

There seems to be a bug in Glassfish v2.1.1 where redeploys or undeploys and deploys are not updating the persistence.xml, which is being cached somewhere. I had to restart the server and then it worked.

Inclusive answered 12/5, 2011 at 9:25 Comment(0)
K
1

In an OSGi-context, it's necessary to list your persistence units in the bundle's MANIFEST.MF, e.g.

JPA-PersistenceUnits: my-persistence-unit

Otherwise, the JPA-bundle won't know your bundle contains persistence units.

See http://wiki.eclipse.org/EclipseLink/Examples/OSGi/Developing_with_EclipseLink_OSGi_in_PDE .

Kerley answered 18/10, 2012 at 9:34 Comment(0)
P
1

You need the following jar files in the classpath:

  1. antlr-2.7.6.jar
  2. commons-collections-3.1.jar
  3. dom4j-1.6.1.jar
  4. hibernate-commons-annotations-4.0.1.Final.jar
  5. hibernate-core-4.0.1.Final.jar
  6. hibernate-entitymanager.jar
  7. hibernate-jpa-2.0-api-1.0.0.Final.jar
  8. javassist-3.9.0.jar
  9. jboss-logging-3.1.1.GA.jar
  10. jta-1.1.jar
  11. slf4j-api-1.5.8.jar
  12. xxx-jdbc-driver.jar
Penance answered 29/6, 2013 at 12:30 Comment(0)
C
1

I just copied the META-INF into src and worked!

Counterplot answered 27/5, 2014 at 9:11 Comment(0)
L
1

Hibernate 5.2.5
Jar Files Required in the class path. This is within a required folder of Hibernate 5.2.5 Final release. It can be downloaded from http://hibernate.org/orm/downloads/

  1. antlr-2.7.7
  2. cdi-api-1.1
  3. classmate-1.3.0
  4. dom4j-1.6.1
  5. el-api-2.2
  6. geronimo-jta_1.1_spec-1.1.1
  7. hibernate-commons-annotation-5.0.1.Final
  8. hibernate-core-5.2.5.Final
  9. hibernate-jpa-2.1-api-1.0.0.Final
  10. jandex-2.0.3.Final
  11. javassist-3.20.0-GA
  12. javax.inject-1
  13. jboss-interceptor-api_1.1_spec-1.0.0.Beta1
  14. jboss-logging-3.3.0.Final
  15. jsr250-api-1.0

Create an xml file "persistence.xml" in

YourProject/src/META-INF/persistence.xml

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>

<persistence 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"
         version="2.1">

<persistence-unit name="sample">

    <class>org.pramod.data.object.UserDetail</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/hibernate_project"/>
        <property name="hibernate.connection.username" value="root"/>
        <property name="hibernate.connection.password" value="root"/>
        <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="false"/>

        <property name="hibernate.cache.use_second_level_cache" value="false"/>

        <property name="hibernate.archive.autodetection" value="true"/>
    </properties>
</persistence-unit>

  1. please note down the information mentioned in the < persistance > tag and version should be 2.1.
  2. please note the name < persistance-unit > tag, name is mentioned as "sample". This name needs to be used exactly same while loading your

EntityManagerFactor = Persistance.createEntityManagerFactory("sample");. "sample" can be changed as per your naming convention.

Now create a Entity class. with name as per my example UserDetail, in the package org.pramod.data.object

UserDetail.java

package org.pramod.data.object;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "user_detail")
public class UserDetail {
    @Id
    @Column(name="user_id")
    private int id;
    @Column(name="user_name")
    private String userName;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }   
    @Override
    public String toString() {
       return "UserDetail [id=" + id + ", userName=" + userName + "]";
    }
}

Now create a class with main method.

HibernateTest.java

package org.pramod.hibernate;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.pramod.data.object.UserDetail;

public class HibernateTest {
    private static EntityManagerFactory entityManagerFactory;

    public static void main(String[] args)  {
        UserDetail user = new UserDetail();
        user.setId(1);
        user.setUserName("Pramod Sharma");

        try {
            entityManagerFactory = Persistence.createEntityManagerFactory("sample");
            EntityManager entityManager = entityManagerFactory.createEntityManager();
            entityManager.getTransaction().begin();
            entityManager.persist( user );
            entityManager.getTransaction().commit();
            System.out.println("successfull");
            entityManager.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

Output will be

UserDetail [id=1, userName=Pramod Sharma]
Hibernate: drop table if exists user_details
Hibernate: create table user_details (user_id integer not null, user_name varchar(255), primary key (user_id))
Hibernate: insert into user_details (user_name, user_id) values (?, ?)
successfull
Lundquist answered 6/12, 2016 at 11:53 Comment(0)
A
1

I had already set up persistence.xml and installed all the Hibernate dependencies and was still stuck with this error.

In my case, I had imported the wrong Persistence class.

I replaced
import javax.persistence.Persistence
with
import jakarta.persistence.Persistence

This solved it. I wish the error message was more descriptive or helpful but there you have it.

Allseed answered 3/4, 2023 at 9:10 Comment(0)
B
0

If there are different names in Persistence.createEntityManagerFactory("JPAService") in different classes than you get the error. By refactoring it is possible to get different names which was in my case. In one class the auto-generated Persistence.createEntityManagerFactory("JPAService")in private void initComponents(), ContactsTable class differed from Persistence.createEntityManagerFactory("JPAServiceExtended") in DBManager class.

Buckjump answered 2/10, 2014 at 10:25 Comment(0)
H
0

Mine got resolved by adding info in persistence.xml e.g. <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> and then making sure you have the library on classpath e.g. in Maven add dependency like

<dependency>
  <groupId>org.eclipse.persistence</groupId>
  <artifactId>eclipselink</artifactId>
  <version>2.5.0</version>
</dependency>
Hesler answered 4/7, 2018 at 6:38 Comment(0)
N
0

Verify the peristent unit name

<persistence-unit name="com.myapp.model.jpa"
    transaction-type="RESOURCE_LOCAL">    
public static final String PERSISTENCE_UNIT_NAME = "com.myapp.model.jpa";
Persistence.createEntityManagerFactory(**PERSISTENCE_UNIT_NAME**);
Notional answered 26/9, 2018 at 8:28 Comment(0)
A
0

In my case it was about mistake in two properties as below. When I changed them ‘No Persistence provider for EntityManager named’ disappered.

So you could try test connection with your properties to check if everything is correct.

<property name="javax.persistence.jdbc.url" value="...”/>
<property name="javax.persistence.jdbc.password" value="...”/>

Strange error, I was totally confused because of it.

Asyut answered 11/7, 2019 at 19:16 Comment(0)
C
0

Try also copying the persistence.xml manually to the folder <project root>\bin\META-INF. This fixed the problem in Eclipse Neon with EclipseLink 2.5.2 using a simple plug-in project.

Clarhe answered 14/1, 2020 at 11:15 Comment(0)
S
0

Had the same issue, but this actually worked for me :

mvn install -e  -Dmaven.repo.local=$WORKSPACE/.repository.

NB : The maven command above will reinstall all your project dependencies from scratch. Your console will be loaded with verbose logs due to the network request maven is making.

Sample answered 15/4, 2020 at 2:35 Comment(0)
S
0

You have to use the absolute path of the file otherwise this will not work. Then with that path we build the file and pass it to the configuration.

@Throws(HibernateException::class)
fun getSessionFactory() : SessionFactory {
    return Configuration()
                .configure(getFile())
                .buildSessionFactory()
    }


private fun getFile(canonicalName: String): File {
    val absolutePathCurrentModule = System.getProperty("user.dir")
    val pathFromProjectRoot = absolutePathCurrentModule.dropLastWhile { it != '/' }
    val absolutePathFromProjectRoot = "${pathFromProjectRoot}module-name/src/main/resources/$canonicalName"
    println("Absolute Path of secret-hibernate.cfg.xml: $absolutePathFromProjectRoot")
    return File(absolutePathFromProjectRoot)
}

GL

Source

Sphygmomanometer answered 27/9, 2020 at 4:21 Comment(0)
W
0

I had the same problem, I removed "@ManagedBean" from my bean class now working.

Woden answered 8/12, 2020 at 2:15 Comment(0)
C
0

I ran into this problem when I moved all my java classes to a different package. Finally, I figured out that if I change the packages of myclasses, then I need to update persistence.xml with the new packages in all the persistence-unit/class elements that refer to my java classes.

Cannot answered 25/7, 2021 at 22:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.