Hibernate 映射资源位于单独的 jar 中

标签 hibernate mapping entity hibernate-mapping hibernate.cfg.xml

我有单独的 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/

相关文章:

sql-server-2005 - 在单个 ASP.NET 应用程序中使用 Entity Framework 的多个版本的 SQL Server

java - 如何在 angularjs 中使用 $resource 来使用 Spring Restful Web 服务

java - Hibernate 预加载(获取所有属性不起作用)

Spring Boot setResultTransformer 和 addScalar

reactjs - React - 将答案显示为列表

c# - 在 Entity Framework 中,如何在没有枚举所有可能 DbSet 的 switch 语句的情况下将通用实体添加到其相应的 DbSet?

java - Spring boot 中的请求是如何生成 JSON 值的?

algorithm - 扑克游戏的商业级随机化

java - 映射异常: Unable to find column with logical name

Linq to Entities 如何在一个数据库访问中更新记录