1
votes

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

1

1 Answers

0
votes

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.