【转】The user must supply a JDBC connection

The user must supply a JDBC connection

hibernate的一个程序就遇到这个错误,google 了一下找到了问题的解决方法。

// *********************************************** //

This is another mistake that's easy to do accidentally, especially by newbies.



If you get a Hibernate error like the one shown above and you're dead sure that your hibernate.cfg.xml is in the classpath, make sure that your initialisation code looks like this:

config = new Configuration();
sessions = config.configure().buildSessionFactory();
// DON'T DO THIS!!!
// sessions = config.buildSessionFactory();

Remember to call the method of when using hibernate.cfg.xml, otherwise this config file won't be picked up by Hibernate.

 

原因:默认 new Configuration(); 会加载默认的 属性配置文件, 即hibernate.properties

若是用的基于XML 的配置文件, 则要调用 configure() 方法来装载配置信息

你可能感兴趣的:(Connection)