最近在做一个项目要用到hibernate annotation,参考着hibernate annotation的文档建立工程,但是在刚建立项目准备测试运行环境的时候却怎么也运行不起来,看日志里的输出信息:
No connection properties specified - the user must supply JDBC connections
明明配置好了为什么还是不能运行了刚开始是这样写的:
import org.hibernate.*;
import org.hibernate.cfg.*;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
[color=red]sessionFactory = new AnnotationConfiguration().buildSessionFactory();[/color]
} catch (Throwable ex) {
// Log exception!
throw new ExceptionInInitializerError(ex);
}
}
public static Session getSession()
throws HibernateException {
return sessionFactory.openSession();
}
}
后来查了以前写的项目才发现hibernate annotation中的文档有误(上边红色标记),这样写是不能读取到hibernate.cfg.xml的,修改方法如下:
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
这样这正确运行了
分享到:
相关推荐
hibernate annotation hibernate3
这里面包涵了需要用Hibernate Annotation时,所需要的所有jar包! 现在我们公司在做web项目的时候,已经不用*.hbm.xml这种映射文件了,都是用Annotation(注解)方式来完成实体与表之间的映射关系,这样看起来比用...
hibernate annotation中文文档
hibernate annotation 中文文档
springmvc + hibernate annotation 配置
Hibernate Annotation
很全的Hibernate Annotation API文档,页面也很漂亮,太强大了。真的很实用!我以前找了好多,都不全,这个真的很不错,推荐一下。
hibernate annotation库所需要引入的三个jar包。
通过HibernateAnnotation技术就不用xml文件了
hibernate annotation3.3 api 文档
hibernate 注解 annotation 教程
Hibernate annotation 3.4 api CHM
逐渐的Hibernate Annotation的映射方式也越来越盛行,相信过不了多久有可能会取代*.hbm.xml映射方式
学习JPA——Hibernate_Annotation使用实例学习JPA——Hibernate_Annotation使用实例学习JPA——Hibernate_Annotation使用实例
该zip包含 hibernate3.3.2相关jar与文档,hibernate annotation3.3.4相关jar与文档。
spring ,hibernate ,flex 应用注释配置的一个例子,里面有数据库脚本和说明文件
java SSH项目 hibernate annotation
hibernate annotation 配置详细!
传统上,Hibernate的配置依赖于外部 XML 文件:数据库映射被定义为一组 XML 映射文件,并且在启动时进行加载。 在最近发布的几个Hibernate版本中,出现了一种基于 Java 5 注释的更为巧妙的新方法。借助新的 ...