我試圖指示休眠的相對(duì)路徑,讓它進(jìn)入休眠狀態(tài).cfg.xml但它不起作用,因?yàn)槲覍戝e(cuò)了(我在文件名中鍵入了cgf而不是cfg)。所以我嘗試了一條絕對(duì)路徑,但Hibernate沒有識(shí)別出新的路徑,并且仍然在查看我以前通過的相對(duì)路徑。但是參數(shù) .configure() 已經(jīng) chenged 了,為什么 Hibernate 忽略并錯(cuò)誤地堅(jiān)持呢?我的代碼: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搜索休眠的錯(cuò)誤屏幕.cfg.xml在我之前作為參數(shù)傳遞的路徑中:現(xiàn)在我已經(jīng)嘗試了這個(gè): SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();錯(cuò)誤消息已更改,但Hibernate仍然沒有找到.cfg.xml:
2 回答

嗶嗶one
TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個(gè)贊
嘗試更新您的 maven 項(xiàng)目:右鍵單擊> Maven > 更新項(xiàng)目。
如果問題仍然存在,請(qǐng)將休眠.cfg.xml文件放在 src 文件夾下。

白衣染霜花
TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超10個(gè)贊
休眠.cfg.xml文件已是類路徑的一部分。您無需指定完整路徑
試試下面的代碼:
SessionFactory sessionFactory = new Configuration().configure( "hibernate.cfg.xml") .buildSessionFactory();
添加回答
舉報(bào)
0/150
提交
取消