4

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

Tioma
  • 2,120
  • 9
  • 35
  • 52
  • your example is incorrect. entities.jar contains a file named `TestEntity.hbm.xml` whereas the hibernate.cfg.xml maps a file named `Test.hbm.xml`... Coincidence? – yair Nov 18 '12 at 22:15

2 Answers2

1

Use method addJar() when creating a new Configuration.

sessionFactory = new Configuration().configure("hibernate.cfg.xml")
   .addJar(new File("/path/to/jar")).buildSessionFactory();
Diego Pino
  • 11,278
  • 1
  • 55
  • 57
0

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.

clemens
  • 16,716
  • 11
  • 50
  • 65
Nayana Shekar C
  • 111
  • 2
  • 6