考虑以下语句:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();其中:
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;如何指定Hibernate将从中检索配置数据的文件?解释说,我有一个具有正确配置数据的hibernate.cfg.xml,但在运行时hibernate抛出错误,引用来自另一个项目的配置,例如:
org.hibernate.MappingNotFoundException: resource: xx/AnotherNonRelatedProject/CertainClass.hbm.xml not found不管怎样,我猜默认配置是从另一个文件开始的。但是我已经搜索了我的hbm.xml文件、类和引用,看起来没问题。
你知道这里会发生什么吗?
Eclipse: Indigo SR2;Hibernate工具: 3.5.1
谢谢!
发布于 2013-03-01 22:00:06
我是在回答我自己的问题,因为我已经发现了我的具体问题,我认为这将是另一个人在问题问题上的问题:
由于我的应用程序是基于Web的,Tomcat的lib文件夹有一个来自另一个项目的.jar文件,该项目存在hibernate配置问题。因为Hibernate会检查与某个项目相关的所有依赖项(包括所有.jar),这包括Tomcat库中的所有jars。因此,在运行时会出现异常(当时对我来说完全陌生)。解决.jar文件的hibernate配置问题,或者从Tomcat文件夹中删除它们(如果没有必要)就解决了这个问题。
发布于 2013-02-28 21:30:54
如果要设置自己的Hibernate配置,则必须使用以下设置:
private static final SessionFactory sessionFactory;
static {
try {
// Create your SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure(new File("hibernate1.cfg.xml"))
.buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}致以最良好的问候:)
https://stackoverflow.com/questions/15136125
复制相似问题