java.lang.NoClassDefFoundError: javax/persistence/EntityListeners解决

环境

MySQL 5.1 + Hibernate 3.2 + MyEclipse 8.6

 

问题

使用Hibernate插入数据,报如下异常:

 

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/EntityListeners
	at org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.getDefaults(JPAMetadataProvider.java:96)
	at org.hibernate.annotations.common.reflection.java.JavaReflectionManager.getDefaults(JavaReflectionManager.java:226)
	at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1385)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1856)
	at com.oracle.entities.Test.main(Test.java:53)
Caused by: java.lang.ClassNotFoundException: javax.persistence.EntityListeners
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
	... 5 more

 

解决

Hibernate需要jpa支持,导入jpajar包(hibernate-jpa-2.0-api-1.0.1.Final.jar)即可。

 

 

参考资料

http://javapub.iteye.com/blog/869380


 


java.lang.NoClassDefFoundError: javax/persistence/EntityListeners解决_第1张图片 java.lang.NoClassDefFoundError: javax/persistence/EntityListeners解决_第2张图片 java.lang.NoClassDefFoundError: javax/persistence/EntityListeners解决_第3张图片
@Wentasy 博文仅供参考,欢迎大家来访。如有错误之处,希望批评指正。原创博文如需转载请注明出处,谢谢 :) [CSDN博客]

你可能感兴趣的:(java.lang.NoClassDefFoundError: javax/persistence/EntityListeners解决)