-->
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.  [ 8 posts ] 
Author Message
 Post subject: Example of Configuration.addJar(...)
PostPosted: Thu Aug 28, 2003 6:29 am 
Newbie

Joined: Wed Aug 27, 2003 10:31 am
Posts: 3
Hi,
I'm getting a NullPointerException when I try:
Configuration config = new Configuration.addJar("commonDomain.jar");

commonDomain.jar is in the java.class.path

I must be doing something stupid - can anyone give me an example of how to use Configuration.addJar?

Thanks,
ct


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 1:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
>> commonDomain.jar is in the java.class.path

I am guessing you mean to say commonDomain.jar is part of the classpath. For example, say you have commonDomain.jar in the directory /java/lib.

If your classpath entry is /java/lib/commonDomain.jar, then the jar file is not on the classpath, it is part of the classpath.

If however, your classpath entry is /java/lib, then it is on the cklasspath and new Configuration.addJar("commonDomain.jar"); should work.


Top
 Profile  
 
 Post subject: Re: Example of Configuration.addJar(...)
PostPosted: Thu Aug 28, 2003 1:31 pm 
Newbie

Joined: Wed Aug 27, 2003 10:31 am
Posts: 3
Quote:
I am guessing you mean to say commonDomain.jar is part of the classpath.


You guess correctly. My bad.

I need commonDomain.jar to be part of the classpath, but I also need a simple way of loading the hibernate mappings contained in it. It look's as if this isn't as simple as I initially hoped it would be.

How would you do this?

Project A:
- Core project with domain objects and hibernate mappings.

Project B:
- Another project with it's own domain objects and hibernate mappings that also needs to make use of the domain objects in project A.

ct


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 1:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I only know "hack" sort of ways to do this.

Here's one:
Code:
String fullPath = Thread.currentThread().getContextClassLoader()
                    .getResource( "mypackage/MyClass.hbm.xml" )
                    .getFile();
String jarPath = fullPath.substring( 0, fullPath.lastIndexOf( "!" ) );
Configuration config = new Configuration().addJar( jarPath );


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 2:52 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 1:02 pm
Posts: 34
Location: Akron, OH
This is how I'm doing it.
Code:
JarInputStream configJar = new JarInputStream(HibernateDAO.class.getClassLoader().getResourceAsStream("hibernate.cfg.jar"));
// get each file inside the jar, 1 per database
for (JarEntry configFile = configJar.getNextJarEntry(); configFile != null; configFile = configJar.getNextJarEntry()) {
    // configure this database
    config.configure("/" + configFile.getName());
    // build session factory and publish in JNDI for lookup
    config.buildSessionFactory();
}

My Ant build.xml puts all my cfg.xml files in hibernate.cfg.jar and builds a hmb.jar for each database. Then my EAR file has

/hibernate.cfg.jar
/Ingres.hbm.jar
/Oracle.hbm.jar
/hibernate2.jar
/otherlibs.jar
/ejb.jar


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 2:54 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 1:02 pm
Posts: 34
Location: Akron, OH
Forgot about this piece. Each *.cfg.xml inside hibernate.cfg.xml has its mapping defined similar to this:

<mapping jar="Ingres.hbm.jar"/>
or
<mapping jar="Oracle.hbm.jar"/>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 29, 2003 2:54 am 
Newbie

Joined: Wed Aug 27, 2003 10:31 am
Posts: 3
efender wrote:
Forgot about this piece. Each *.cfg.xml inside hibernate.cfg.xml has its mapping defined similar to this:

<mapping jar="Ingres.hbm.jar"/>
or
<mapping jar="Oracle.hbm.jar"/>


What's the difference between Oracle.jar and Ingres.jar - surely the hibernate mapping files are the same regardless of the underlying database?

Will <mapping jar="commonDomain.jar"/> only find hbm.xml files in the root of the jar, or will it recurse the contents of the jar looking for hbm.xml files?

Thanks,
ct


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 29, 2003 8:23 am 
Beginner
Beginner

Joined: Tue Aug 26, 2003 1:02 pm
Posts: 34
Location: Akron, OH
ciaran wrote:
What's the difference between Oracle.jar and Ingres.jar - surely the hibernate mapping files are the same regardless of the underlying database?

I probably could put all of my mappings in the same jar. I never really considered that. I just did it that way to logically group them together.

Also, the mapping section of the config xml is required, so I have to put something there in each one. If the mapping section was optional, I'd probably load everything together in 1 jar programatically. I suppose I could specify an empty jar in the config xml, then after all of the databases are configured load everything with a Configuration.addJar(jarName), but that's a nasty hack.


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