我有单独的 jar 文件已经包含 hibernate 实体映射和直接映射。我的 Hibernate 配置文件 (cgf.xml) 放在另一个 jar 文件中。结果我捕获了异常“资源:com/iceleads/data/Test.hbm.xml not found”。
例子:
entities.jar
com.package.entity.TestEntity.java
com.package.entity.TestEnity.hbm.xml
mainUsage.jar
com.package.main.MainClass.java - there are I get session factory
SessionFactory factory = HibernateUtil.getSessionFactory();
com.package.main.hibernate.cfg.xml
in HibernateUtil
sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
in hibernate.cfg.xml
<mapping resource="com/package/entity/TestEntity/Test.hbm.xml"/>
mainUsage.jar 类路径中的entities.jar
请建议我如何配置 hibernate.cfg.xml 以将单独的 jar 与实体一起使用。
非常感谢!
阿尔特姆
最佳答案
使用方法addJar()
创建新配置时。
sessionFactory = new Configuration().configure("hibernate.cfg.xml")
.addJar(new File("/path/to/jar")).buildSessionFactory();
关于Hibernate 映射资源位于单独的 jar 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5391711/