【发布时间】:2010-12-19 06:22:56
【问题描述】:
我使用 Hibernate 创建了一个小型桌面项目,以了解如何在其中应用企业模式。
我正在使用注释,并编写了一个类来包装我的会话工厂
public class Hibernation {
private static final SessionFactory sessionFactory;
static{
try{
//sesionFactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory();
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
}
catch(Throwable e){
throw new ExceptionInInitializerError(e);
}
}
public static Session getSession(){
return sessionFactory.openSession();
}
}
但是,每当我尝试运行它时,我都会收到此错误:
原因:java.lang.ClassNotFoundException: javax.persistence.ElementCollection
我的类路径中的 jars 中似乎没有该类
hibernate3.jar
jpa.jar
log4j-1.2.15.jar
persistence-api-1.0.jar
slf4j-log4j12-1.0.1.jar
我已经四处寻找该课程,但找不到从哪里下载。知道我缺少什么 jar 文件吗?我查看了javaee.jar 内部,那里有许多 javax.persistence.*** 类,但也不存在。
提前致谢。
【问题讨论】:
-
请使用较新版本的 Hibernate。版本应该大于 3.5 或者最好使用 Hibernate 4.0。请使用以下链接下载适合的版本sourceforge.net/projects/hibernate/files
标签: hibernate annotations hibernate3 java