一个很弱的问题,高手们不吝赐教:
我把hibernate.cfg.xml文件放在src目录下,用new Configuration.configure()方法可以读取配置文件,但改用new Configuration.configure("hiberate.cfg.xml")就总是提示“找不到hibernate.cfg.xml文件”,是怎么回事呢?文件路径不对吗?但我看一些文章里说只要放在classpath下就行了啊。
new Configuration.configure() 会在默认的路径下找hiberate.cfg.xml配置文件,请看源代码:
[code="java"]
public Configuration configure() throws HibernateException {
configure( "/hibernate.cfg.xml" );
return this;
}
[/code]
所以你应该是:
[code="java"]
Configuration.configure("/hiberate.cfg.xml")
[/code]
看看你的classpath的设置是什么?
看过这个了吗?可能有你想要的答案。
『提问』客户端测试时hibernate.cfg.xml的存放位置。 [url]http://www.iteye.com/topic/5458[/url]
Configuration是hibernate的入口,在新建一个Configuration的实例的时候,使用不带参数的configure ()方法,hibernate会在classpath里面查找配置文件;Configuration的configure ()方法还支持带参数的访问方式,[color=red]你可以指定hbm.xml文件的位置[/color],而不是使用默认的classpath下面的配置文件。应该指定配置文件的位置。
貌似就是楼上的这个了