JPA problem with service jar on Windows

I have a problem with JPA on windows.

I create a vaadin project using Netbeans 8.2 on Linux (Mint) and a java project that contains the jpa entities of my aplication with some DAOs. I’m using EclipseLink on both projects.

On linux, this scheme works well, but on Windows I get this error:

java.lang.NoClassDefFoundError: org/dom4j/Element at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory( at javax.persistence.Persistence.createEntityManagerFactory( at javax.persistence.Persistence.createEntityManagerFactory( at com.relpro.web.relpro.util.RelproPortalUtils.getEntityManager( ... For some reason, the provider ‘change’ to Hibernate.
someone else had this problem?

On the last line, I create the EntityManager in a class from my vaadin project that use EclipseLink.

public static EntityManager getEntityManager() { EntityManagerFactory emf = Persistence.createEntityManagerFactory("relproPU"); return emf.createEntityManager(); } Many thanks.

Hi, which server are you using? All Java EE servers provide JPA implemenentation, maybe a built in JPA implementation is used instead of EclipseLink (that you provide as a project dependency ?)


Hi Matti,
I’m using Tomcat 8.0.18, but I think I found the problem.

On my dependencies I have more than one jar with the file “META-INF/services/javax.persistence.spi.PersistenceProvider”:

  • eclipselink-2.5.2.jar → that’s contains ‘org.eclipse.persistence.jpa.PersistenceProvider’
  • demo.jar → that’s contains ‘org.hibernate.ejb.HibernatePersistence’

I check this with the next code:

PersistenceProviderResolver resolver = PersistenceProviderResolverHolder.getPersistenceProviderResolver(); List<PersistenceProvider> providers = resolver.getPersistenceProviders(); System.out.println("---------"); for (PersistenceProvider provider : providers) { System.out.println(provider.getClass()); } System.out.println("---------"); In my case, on Linux prints:

class org.eclipse.persistence.jpa.PersistenceProvider
class org.hibernate.ejb.HibernatePersistence

But on Windows prints:

class org.hibernate.ejb.HibernatePersistence
class org.eclipse.persistence.jpa.PersistenceProvider

I’m trying to find a clean way to resolve this problem (I can’t remove ‘demo.jar’ without a big refactor)
For now, i just simple remove ‘HibernatePersistence’ from the list ‘providers’.

Many thanks, Matti … great blog! :smiley: