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/T开发者_如何学Goest.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.
精彩评论