Published on Sep 24 2014 in Java

One of possible causes for java.lang.NoClassDefFoundError: javax/persistence/EntityListeners

java.lang.NoClassDefFoundError: javax/persistence/EntityListeners
org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.getDefaults(JPAMetadataProvider.java:97)
org.hibernate.annotations.common.reflection.java.JavaReflectionManager.getDefaults(JavaReflectionManager.java:226)
org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1352)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1777)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1861)
com.util.HibernateUtil.getSession(HibernateUtil.java:16)

It is usually caused by missing hibernate-jpa jars. These may be included in your development environment but mising in the generated WAR. You need to ensure the JPA jar is included in your WAR's WEB-INF/lib or your application server's global lib directory or somewhere else in the classpath.

For example for Hibernate 4.2.6 it can be found in hibernate-release-4.2.6.Final.tgz (hibernate-release-4.2.6.Final/lib/required/hibernate-jpa-2.0-api-1.0.1.Final.jar). For other versions it can be in an other file or location as hibernate parts were moved recently between jars. For example hibernate-distribution-3.6.0.Final-dist.zip keeps it in hibernate-distribution-3.6.0.Final/lib/hibernate-jpa-2.0-api-1.0.0.Final.jar.

Hibernate versions earlier than 3.6 were using modules for annotations, entitymanager and core. Core (distributed as hibernate3.jar) had no JPA dependency.