I have a problem with java jdk1.6.0_17 and hibernate . I must open an hibernate session factory but mapping file (mapper-test.jar) is load by a custom classLoader (URLClassLoader) - the web app is deployed on JBoss 4.3.2
File map = new File("/opt/mapper/mapper-test.jar"); File map1 = new File("/opt/mapper/hibernate3.jar"); URL[] urls = new URL[] { map.toURI().toURL(),map1.toURI().toURL()}; URLClassLoader loader = new URLClassLoader(urls); //test load is ok loader.loadClass("com.mydomain.dao.app.IcFabb"); Configuration configuration=new Configuration(); configuration.configure( loader.getResource("hibernate.cfg.xml")); // the following statement will throw a MappingException configuration.buildSessionFactory();
this is the throwed Exception:
org.hibernate.MappingException: Resource: com/mydomain/dao/app/IcFabb.hbm.xml not found at org.hibernate.cfg.Configuration.addResource(Configuration.java:479) at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390) at org.hibernate.cfg.Configuration.configure(Configuration.java:1325) at testLoad.main(testLoad.java:32)
the hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="dialect">org.hibernate.dialect.SQLServerDialect</property> <property name="show_sql">true</property> <property name="hibernate.cache.use_query_cache">false</property> <property name="hibernate.cache.use_second_level_cache">false</property> <property name="hibernate.jdbc.use_scrollable_resultset">true</property> <mapping resource="com/mydomain/dao/app/IcFabb.hbm.xml"/> </session-factory> </hibernate-configuration>
Seems that the Configuration searches the file com/mydomain/dao/app/IcFabb.hbm.xml in the system classloader and not in the URLClassLoader, so how do I connect the Configuration with the Loader?
Thank you
|