简体   繁体   中英

Issue while renaming persistence.xml in JPA,hibernate using EclipseLink

I was facing the following exception while creating createEntityManagerFactory though I have persistence.xml in META-INF folder and persistence unit ABC is present in persistence.xml and persistence provider is hibernate as follows.

<persistence-unit name="ABC" transaction-type="RESOURCE_LOCAL"> 
    <provider>org.hibernate.ejb.HibernatePersistence</provider>

exception

javax.persistence.PersistenceException: No Persistence provider for EntityManager named ABC

at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)

So I thought createEntityManagerFactory is not referring to correct persistence.xml file and I changed the persistence-alternative.xml and I used the following piece of code to refer to persistence-alternative.xml

EntityManagerFactory emf = objEmfMap.get(unitName);
    try{
        Properties pros = new Properties();

        pros.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, 
                         "META-INF/persistence-alternative.xml");
        // check if the entity manager factory is available for the unit else create            
        if (emf == null) {
            emf = Persistence.createEntityManagerFactory(unitName,pros);
            objEmfMap.put(unitName, emf);
        }

And I placed persistence-alternative.xml in META-INF folder. But still I'm facing the same exception.

javax.persistence.PersistenceException: No Persistence provider for EntityManager named ABC at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)

Guys please let me know How to fix this issue..

Thanks in Advance

When you make changes in a configuration file, like persistence.xml, it might help to clean and rebuild your project. Go the the menu and select Project - Clean.... If Eclipse is not set to build projects automatically, then select Project - Build Project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM