Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/Cacheable 问题
2012-03-22 08:42
429 查看
我用annotations做hibernate操作时报这个错误请问是什么原因: Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/Cacheable at org.hibernate.cfg.AnnotationBinder.determineCacheSettings(AnnotationBinder.java:953) at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:596) at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:636) at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:359) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1377) at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954) at TeacherTest.main(TeacherTest.java:17) 环境,hibernate3.5.5_annotations3.4.0 两个java类 TeacherTest import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.Configuration; import com.bjsxt.hibernate.model.Teacher; public class TeacherTest { public static void main(String[] args){ Teacher t=new Teacher(); t.setId(1); t.setName("t1"); t.setTitle("教受"); Configuration cfg=new AnnotationConfiguration(); SessionFactory sf=cfg.configure().buildSessionFactory(); Session session=sf.openSession(); session.beginTransaction(); session.save(t); session.getTransaction().commit(); session.close(); sf.close(); } } Teacher package com.bjsxt.hibernate.model; import javax.persistence.Entity; import javax.persistence.Id; @Entity public class Teacher { private int id; private String name; private String title; @Id public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } } hibernate.cfg.xml中的mapping <mapping class="com.bjsxt.hibernate.model.Teacher"/>
解决办法:
javax.persistence.Cacheable 是 JPA 2.0 规范中的东西! 需要加入hibernate-distribution-3.5.0-Final\lib\jpa目录下的hibernate-jpa-2.0-api-1.0.0.Final.jar 到path中
步骤:window->preferences-java->bulid path-userliberlay-hibernate-->add JARs->选择你的hibernate-jpa-2.0-api-1.0.0.Final.jar目录名,保存重新编译,问题解决
相关文章推荐
- Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/Cacheable
- Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/Cacheable 问题
- Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/Cacheable
- Exception in thread "main" java.lang.NoSuchMethodError: javax.persistence.OneToOne.orphanRemoval()Z
- Exception in thread "main" java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z
- Exception in thread "main" java.lang.NoSuchMethodError: javax.persistence.OneToOne.orphanRemoval()Z
- Exception in thread "main" java.lang.UnsupportedClassVersionError: 问题
- JDK版本问题Exception in thread &quot;main&quot; java.lang.UnsupportedClassVe
- 问题描述 Exception in thread "main" java.lang.OutOfMemoryError: Java heap space 解决方案[转] 一直都知道可以设置jvm he
- Exception in thread "main" java.lang.NoClassDefFoundError: hello/class 问题解决
- hibernate Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException
- Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/Synchronization
- Exception in thread "main" java.lang.NoClassDefFoundError问题
- Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/SystemException
- Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/Synchronization
- Exception in thread "main" java.lang.NoClassDefFoundError 问题的解决办法
- Eclipse下好使,但是cmd下执行java运行class文件提示Exception in thread "main" java.lang.NoClassDefFoundError问题
- Exception in thread "main" java.lang.NoClassDefFoundError 问题及其解决方法
- 解决Exception in thread "main" java.lang.OutOfMemoryError: Java heap space问题
- Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/Synchronization