No CurrentSessionContext configured!" 異常解決方案

來源:互聯網
上載者:User

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 >

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.