`
esffor
  • 浏览: 1351368 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

No CurrentSessionContext configured!" 异常解决方案

阅读更多

hibernate 老说没有配方言

<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
这句话明明就写在了配置文件里面,可老是没有写
错误如下:
Exception in thread "main" org.hibernate.HibernateException: Hibernate Dialect must be explicitly set

name改成"hibernate.dialect"也不行

Hibernate-Version: 3.1.1
mysql -Verison: 4.0.16


用这种方法正确
static {

try {
configuration = new Configuration();

sessionFactory = configuration.configure().buildSessionFactory();
} catch (Throwable ex) {

 

throw new ExceptionInInitializerError(ex);
}
}

这种方式会出现异常
// static {
// try {
// // Create a configuration based on the properties file we've put
// Configuration config = new Configuration();
// config.addClass(Customer.class).addClass(Order.class);
// // Get the session factory we can use for persistence
// sessionFactory = config.buildSessionFactory();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }

第二种方式是针对使用properties文件配置hiernate的写法,使用hibernate.cfg.xml应使用第一种调用方式

或者在hibernate.cfg.xml中加入:

 

<property name="current_session_context_class">thread</property>

 



分享到:
评论
2 楼 shisanshe 2013-12-11  
我也是这个问题,加了<property name="current_session_context_class">thread</property>
1 楼 pangchaofu 2010-02-23  
找了好久,终于解决了,谢谢。

相关推荐

Global site tag (gtag.js) - Google Analytics