简体   繁体   English

hibernate 没有找到 hibernate.cfg.xml 文件

[英]hibernate is not locating hibernate.cfg.xml file

I'm using Hibernate framework and I have the problem that it always looks for the hibernate.cfg.xml file inside test/resources/META-INF/ folder, in testing or when I run the app.我正在使用 Hibernate 框架,但我遇到的问题是它总是在 test/resources/META-INF/ 文件夹中查找 hibernate.cfg.xml 文件,在测试中或运行应用程序时。

The configuration is this one:配置是这样的:

object hibernateUtils{
  private val cfg = new Configuration
  cfg.configure("META-INF/hibernate.cfg.xml")
  val sessionFactory = cfg.buildSessionFactory
}

Always looks for the test configuration, and I don't want to put an absolute path, I want it to look for the file inside the resource folder.总是找测试配置,不想放绝对路径,我想让它在资源文件夹里面找文件。

The configuration object is under main/scala/utils/.配置对象在 main/scala/utils/ 下。 I'm using hava and scala in the app.我在应用程序中使用了 hava 和 scala。

Does anyone know how can I solve this?有谁知道我该如何解决这个问题? Thank you!谢谢!

Have you tried with你有没有试过

cfg.configure("classpath:utils/META-INF/hibernate.cfg.xml")

If it doesn't work, just check where the classpath is pointing to and use relative path from there.如果它不起作用,只需检查类路径指向的位置并从那里使用相对路径。

为什么将 hibernate cfg 放在 META-INF 而不是 src ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM