Hibernate 不更新搜索 hibernate.cfg.xml 的路径

我试图指示休眠获取 hibernate.cfg.xml 的相对路径,但它不起作用,因为我写错了(我在文件名中输入了 cgf 而不是 cfg)。所以我尝试了绝对路径,但 Hibernate 无法识别新路径,并且仍在查看我之前通过的相对路径。但是参数 .configure() 已经改变了,为什么 Hibernate 会忽略并坚持错误呢?


我的代码:


private static SessionFactory buildSessionFactory() {

        Configuration configuration = new Configuration();


        //  Use the mappings and properties specified in an application resource named hibernate.cfg.xml.

        configuration.configure("C:\\Users\\Lucas_Pletsch\\eclipse-workspace\\PDV\\main\\resources\\hibernate.cfg.xml");

显示 Hibernate 在我之前作为参数传递的路径中搜索 hibernate.cfg.xml 的错误屏幕:

http://img4.mukewang.com/62e09d760001480413650770.jpg

现在我已经尝试过了:

 SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();

并且错误信息已经改变,但是 Hibernate 仍然没有找到 .cfg.xml:

http://img1.mukewang.com/62e09d860001316b13670773.jpg

阿晨1998
浏览 140回答 3
3回答

一只甜甜圈

尝试更新您的 Maven 项目:右键单击 > Maven > 更新项目。如果问题仍然存在,请将 hibernate.cfg.xml 文件放在 src 文件夹下。

牛魔王的故事

将您的项目更新为:右键单击项目->选择 Maven->然后选择更新项目

DIEA

您的 hibernate.cfg.xml 文件已经是类路径的一部分。您无需指定完整路径试试下面的代码:SessionFactory sessionFactory = new Configuration().configure(                     "hibernate.cfg.xml")                     .buildSessionFactory();
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java