【问题标题】:Hibernate mapping resource locate in the separate jarHibernate 映射资源位于单独的 jar 中
【发布时间】:2011-07-20 11:42:14
【问题描述】:

我有单独的jar文件已经包含了hibernate实体映射和直接映射。我的 Hibernate confg (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 与实体一起使用。

非常感谢!

阿尔泰姆

【问题讨论】:

  • 您的示例不正确。 entity.jar 包含一个名为 TestEntity.hbm.xml 的文件,而 hibernate.cfg.xml 映射一个名为 Test.hbm.xml 的文件...巧合吗?

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


【解决方案1】:

在映射资源中包含映射文件的路径。比如使用&lt;mapping resource="com/example/test/test.hbm.xml"/&gt;test.hbm.xml位于jar文件内的包com.example.test中。

这将达到目的。

【讨论】:

    【解决方案2】:

    创建新配置时使用方法addJar()

    sessionFactory = new Configuration().configure("hibernate.cfg.xml")
       .addJar(new File("/path/to/jar")).buildSessionFactory();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 1970-01-01
      • 2014-10-02
      • 2015-09-12
      • 1970-01-01
      • 2010-12-27
      • 1970-01-01
      相关资源
      最近更新 更多