This post provides possible exception while doing the JPA programming and the suggested solution for resolving the exception. This post will solve the issue that can be happened while the JPA implementation trying to get a persistence provider. The exception explained in this post thrown when you have not configured properly the persistence unit name in the persistence.xml.
Look at the following example:
EntityManagerFactory factory = Persistence.createEntityManagerFactory("EclipseLink-JPA-Installation"); <span style="font-size: 12px; line-height: 18px;">
When we are coming to execute an application contains the above snippet of code, we might got the following persistence exception:
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named EclipseLink-JPA-Installation at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54) at net.javabeat.eclipselink.JPAImpl.main(JPAImpl.java:12) <span style="font-size: 12px; line-height: 18px;">
Such that exception notify you for reviewing the persistence.xml file that located under META-INF which in turn located under your source code. Check your persistence-unit name, you almost probably have a wrong name of the persistence unit or you have no persistence at all.
If you have a persistence unit in the persistence.xml, you have make sure that the persistence unit name is identical to the name that is passed into createEntityManagerFactory method. But if you have no persistence unit at all, you have to create it.
Note : The exception solution is only the possible, it is common that same exception could be thrown for multiple reasons which is not explained in this tutorial. If you come across any such scenario, please write it in the comments section.
To know more about how to create EclipseLink and JPA project, please read our previous tutorial eclipselink jpa installation and configuration.