-1

Stack Trace :

Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named Sample
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
    at cm.cvs.service.UserInfoService.<init>(UserInfoService.java:32)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
    ... 24 more

Jar used :

enter image description here

Placed persistence.xml under META-INF folder. enter image description here

Persistence.xml

enter image description here

In persistence.xml, i have already given provider property.

Mikko Maunu
  • 41,366
  • 10
  • 132
  • 135
  • 1
    WTF is that "provider" ? You are supposed to specify the IMPLEMENTATION class of a JPA Provider there, not the interface. So define your implementation being used DataNucleus? EclipseLink? Hibernate? OpenJPA ? and look in their docs for the provider name – Neil Stockton Dec 26 '16 at 18:50
  • Possible duplicate of [No Persistence provider for EntityManager named](http://stackoverflow.com/questions/1158159/no-persistence-provider-for-entitymanager-named) – Christian W Dec 26 '16 at 21:34
  • @ChristianW it is not a duplicate. from the answer of "No Persistence provider for EntityManager named", i have already used that answer to resolve it. but still it was not working. – Ganesh Kumar Palaniappan Dec 27 '16 at 05:02
  • So in your current persistence.xml you have org.hibernate.ejb.HibernatePersistence as implementation instead of javax.persistence.spi.PersistenceProvider ? – Christian W Dec 27 '16 at 10:41
  • Now the issue got resolved and i have no provider tag is used in my persistence.xml – Ganesh Kumar Palaniappan Dec 27 '16 at 11:32

1 Answers1

0

When doing JPA under web application project, place persistance.xml in "src/META-INF" path and remove the below line from persistence.xml

<provider>javax.persistence.spi.PersistenceProvider</provider>

Note: META-INF folder was newly created under src folder.

Got reference from this link to resolve the error.

First tried to create simple java jpa application to check whether i am getting the same here also.

But it worked fine. when i replaced the java application persistence.xml with my web application persistence.xml, that time it throwed same error.

after comparing both persistence.xml, i removed the line "javax.persistence.spi.PersistenceProvider" from the web application's persistence.xml and kept under src/META-INF then it worked fine.

  • 1
    which completely ignores the root cause ... putting the CORRECT value for "provider" for your chosen JPA provider. You can only not put the "provider" element when you only have 1 provider in your CLASSPATH. As soon as you have multiple present then this "solution" fails – Neil Stockton Dec 27 '16 at 11:47