Hello,
Hibernate version: 3.2.4
I am building a web app that uses hibernate. This app is binded to another project (foo.jar) which also uses hibernate. All hibernate related tasks (transaction demarcation, etc ) are implemented in foo project and lie within foo.jar. The secondary project (foo) also includes several mapping documents that are essential for the root web app to function properly. Hibernate configuration (hibernate.hbm.cfg) is placed in the web app classpath and not in the jar file. A snippet of the document is the following:
hibernate.hbm.cfg:
Code:
<mapping jar="../lib/foo.jar" />
<mapping resource="bar/model/Item.hbm.xml" />
<mapping resource="bar/model/ResourceItem.hbm.xml"
At runtime, or when running schema updates, foo.jar is successfully found, as it lies in the web app classpath as well, and so are the mapping documents. The problem is that I get a MappingException that the mapped pojo properties do not exist. This is caused by a ClassNotFoundException for the .class files of the entities that are mapped within the foo.jar. Of cource, everything is exactly where it supposed to be, so I am thinking that is a ClassLoader issue as the exceptions indicate. The web app can easily trace bar/model/Item.hbm.xml and foo.jar but it seems that it cannot find the necessary classes within the jar when it comes to mappings.
The full stack trace:
Code:
org.hibernate.InvalidMappingException: Could not read mapping documents from jar: foo.jar
at org.hibernate.cfg.Configuration.addJar(Configuration.java:621)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1591)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.main(SchemaUpdate.java:76)
Caused by: org.hibernate.MappingException: class foo.Foo not found while looking for property: username
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:74)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2174)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2151)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2041)
at org.hibernate.cfg.HbmBinder.bindJoinedSubclass(HbmBinder.java:897)
at org.hibernate.cfg.HbmBinder.handleJoinedSubclass(HbmBinder.java:2212)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2114)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2041)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:359)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
at org.hibernate.cfg.Configuration.add(Configuration.java:669)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:504)
at org.hibernate.cfg.Configuration.addJar(Configuration.java:618)
... 6 more
Caused by: java.lang.ClassNotFoundException: foo.Foo
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:70)
... 20 more
Is there a solution to this problem?? Am I doing something the wrong way??
Thanks in advance,
akz