-->
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.  [ 7 posts ] 
Author Message
 Post subject: load classes and *.hbm.xml from jar file not in classpath
PostPosted: Mon Dec 22, 2003 4:39 pm 
Beginner
Beginner

Joined: Wed Sep 10, 2003 5:32 pm
Posts: 28
Hi everyone,

In hibernate standpoint, is there anyway that I can dynamically load all the class files and *.hbm.xml files during runtime from a jar file but the jar file is not included in the classpath. I know that I can dynamically load any java classes during runtime from a jar file as long as I use the appropriate ClassLoader and classloader understands where to load those classes. Is there anyway that I can pass appropriate ClassLoader into hibernate so that hibernate will load classes appropriately even though jar file is not in the class path but classloader will understand where to look for those files??

Vivian


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 8:07 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Read the file yourself as a DOM and use the appropriate add method (addDocument from memory)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 8:39 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
Emmanuel,


I believe Vivian is asking a different question, and I am interested in the answer, too.


Say you have some code generator (ie. Middlegen, AndroMDA + Ant etc etc) that can generate a JAR with your Hibernate classes and hbm.xmls.

Now you want to deploy that new JAR into a running environment, such as JBoss (which you probably can do some things via hot deploy) or maybe a straight JVM, and have the environment process that JAR and allow Hibernate activity to use the new classes ec.

I have a very metadata driven product that does things like generate HQL on the fly, so I will need to deploy JARs like this.


Vivian, does this outline what you want to do?

Emannuel, any suggestions?



Thanks,


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 23, 2003 11:05 am 
Beginner
Beginner

Joined: Wed Sep 10, 2003 5:32 pm
Posts: 28
Hi everyone

Sherman - Yes, it outlined what I want.

I need to mention that I have no problem on feeding the *.hbm.xml from the jar into hibernate without any problem - that is easy. When the binder is trying to bind appropriate *.hbm.xml with appropriate *.class file - I run into problem with Hibernate. I am using a custom classloader to read those *.class files, Hibernate has no idea about the custom classloader and I need to use Thread.currentThread().setContextClassloader() in order to pass in the custom classloader for Hibernate to class load appropriate classes and I do not like that. I wish that Hibernate can have a configuration method that will take in custom classloader and actually use the custom classloader later to bind *.class with *.hbm.xml. Now I can only use Thread.currentThread().setContextClassLoader() to set classloader and I do not like this solution at all. I would like to ask if anyone has any solution for this one besides setting Thread.currentThread().setContextClassLoader()?? I know there is a method in configuration called addResource(String path, Classloader classloader) that I can use but it still does not satisfy the binding scenario because classloader is only used to retrieve *.hbm.xml file and configuration will not store classloader and use it later on binding.


Vivian


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 23, 2003 11:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
eh - why is Thread.currentThread().setContextClassLoader() bad ? that is the most correct way to fuck up...to correct classloading!?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 23, 2003 1:32 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
max wrote:
eh - why is Thread.currentThread().setContextClassLoader() bad ? that is the most correct way to fuck up...to correct classloading!?


I don't follow. Are you saying setContextClassLoader() is bad (agreeing with Vivian) or good?


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 23, 2003 1:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
setContextClassLoader() is good (normally!)

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.