当前位置:编程学习 > JAVA >>

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

环境
MySQL 5.1 + Hibernate 3.2 + MyEclipse 8.6
 
 
 
问题
使用Hibernate插入数据,报如下异常:
 
 
 
[java] 
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  www.zzzyk.com
 
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支持,导入jpa的jar包(hibernate-jpa-2.0-api-1.0.1.Final.jar)即可。
 
 
 
 
 
补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,