문제

I have separate jar file has contain hibernate entity mapping and mapping directly. My Hibernate confg (cgf.xml) placed in another jar file. And as result I catch exception "resource: com/iceleads/data/Test.hbm.xml not found".

Example:

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 in mainUsage.jar classpath

Please suggest me how I can configure hibernate.cfg.xml to use separate jar with entities.

Thanks a lot!

Artem

도움이 되었습니까?

해결책

Use method addJar() when creating a new Configuration.

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

다른 팁

Including the path of the mapping file into the mapping resource. For instance, use <mapping resource="com/example/test/test.hbm.xml"/>, and test.hbm.xml is located in the package com.example.test inside the jar file.

This will serve the purpose.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top