-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Read mapping documents from .jar and ClassLoader
PostPosted: Wed Jul 11, 2007 7:23 am 
Newbie

Joined: Fri Mar 16, 2007 6:04 am
Posts: 14
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 9:28 am 
Newbie

Joined: Fri Mar 11, 2005 4:38 am
Posts: 9
Location: Ukraine, Kiev
Could you post packaging structure of your application. It seems that you're referencing jar file with mappings in wrong way.

_________________
Oleg


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 9:44 am 
Newbie

Joined: Fri Mar 16, 2007 6:04 am
Posts: 14
Code:

Root Web application:


- default package
  |------ application.properties
  |------ log4j.properties
  |------ hibernate.hbm.cfg
- bar
  |------ action
  |       |---- EditAction.java
  |       |---- DeleteAction.java   
  |------ model
  |       |---- Item.java
  |       |---- Item.hbm.xml
  |       |---- ResourceItem.java
  |       |---- ResourceItem.hbm.xml
  |------ util
         |---- StringUtil.java
         |---- DateUtil.java
        
        
Inside foo.jar:

- foo
  |------ Foo.class
  |------ Foo.hbm.xml
  |------ Bar.class
  |------ Bar.hbm.xml
  |------ hibernate
           |------ HibernateUtil.class




Any help would be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 10:13 am 
Newbie

Joined: Fri Mar 11, 2005 4:38 am
Posts: 9
Location: Ukraine, Kiev
What is a structure of your war file. Is it like this?
Code:
bar.war
  |_WEB-INF
     |_lib
     |    |_foo.jar
     |_classes
          |_bar specific classes and hibernate.cfg.xml

_________________
Oleg


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 10:24 am 
Newbie

Joined: Fri Mar 16, 2007 6:04 am
Posts: 14
yeap


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 10:38 am 
Newbie

Joined: Fri Mar 11, 2005 4:38 am
Posts: 9
Location: Ukraine, Kiev
Could you send me your project on email (see profile). I'll try to help. Also I'd like to know what server do you use.

_________________
Oleg


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 10:53 am 
Newbie

Joined: Fri Mar 16, 2007 6:04 am
Posts: 14
Unfortunately it's about production code and I can't. My server is Tomcat 5.5.
Thanks, anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 10:59 am 
Newbie

Joined: Fri Mar 11, 2005 4:38 am
Posts: 9
Location: Ukraine, Kiev
It could be equivalent Foo-Bar example made on quick hand. I can make it myself but I can't be sure I'll reproduce your situation.

_________________
Oleg


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 11:10 am 
Newbie

Joined: Fri Mar 11, 2005 4:38 am
Posts: 9
Location: Ukraine, Kiev
I'm not sure, but you could try to change
Code:
<mapping jar="../lib/foo.jar" />

to
Code:
<mapping jar="foo.jar" />


Take a look at http://www.developer.com/open/article.php/10930_3559931_3 (Configuring the SessionFactory section)

_________________
Oleg


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.