4

我有單獨的jar文件包含了hibernate的實體映射和直接映射。我的Hibernate confg(cgf.xml)放在另一個jar文件中。結果我發現異常「resource:com/iceleads/data/Test.hbm.xml not found」。休眠映射資源定位在單獨的jar中

例子:

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"/> 

entities.jar在mainUsage.jar classpath中

請建議我我如何可以配置hibernate.cfg.xml中使用單獨的罐子實體。

非常感謝!

阿爾喬姆

+0

你的例子不正確。 entities.jar包含一個名爲'TestEntity.hbm.xml'的文件,而hibernate.cfg.xml映射一個名爲'Test.hbm.xml'的文件......巧合? – yair 2012-11-18 22:15:49

回答

1

使用方法創建一個新的配置時addJar()

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

將映射文件的路徑包含到映射資源中。例如,使用<mapping resource="com/example/test/test.hbm.xml"/>,並且test.hbm.xml位於jar文件內的包com.example.test中。

這會達到目的。