-->
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.  [ 13 posts ] 
Author Message
 Post subject: Accessing .hbm.xml that resides in a JAR
PostPosted: Thu Nov 03, 2005 8:33 am 
Regular
Regular

Joined: Fri Sep 30, 2005 6:15 am
Posts: 50
Hello,

I have several web applications accessing same POJO used to map my tables with hibernate, so I decided to put these POJO and their "*.hbm.xml" into one JAR that I put in the classpath of my web applications...

Then in my web application, I have the file hibernate.cfg.xml where I define the path for my "*.hbm.xml" files => but it doesn't work...
And if I moved the files from my jar to my web application project => it works!

why?
is it possible? If not any idea how to do?

TIA


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 8:59 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Please show you cfg.xml file.

TIA
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 9:04 am 
Regular
Regular

Joined: Fri Sep 30, 2005 6:15 am
Posts: 50
Thanks for help!

Here is my hibernate.cfg.xml

If you see something strange...

Note : The file "org/wgt/base/mapping/Contact.hbm.xml" is in a JAR file defined in my classpath....so...


Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory name="HibernateSessionFactory">

        <!-- Database connection settings -->
        <property name="hibernate.connection.datasource">jdbc/WGTDB</property>
        <property name="hibernate.connection.username">db2user</property>
        <property name="hibernate.connection.password">db2pass</property>


        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.DB2Dialect</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
   

        <mapping resource="org/wgt/base/mapping/Contact.hbm.xml"/>

    </session-factory>

</hibernate-configuration>
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 12:03 pm 
Regular
Regular

Joined: Fri Sep 30, 2005 6:15 am
Posts: 50
Please, just tell me if it posible to have hbm.xml file embedded into a JAR?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 12:48 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
this can and does work. retrace your steps, it's probabaly something simple.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 2:16 pm 
Beginner
Beginner

Joined: Thu Jan 22, 2004 8:22 pm
Posts: 48
I use mapping files in jars for all my web application. I don't use the XML config format but one thing that looks odd to me is that in the mapping element that names the mapping file I always have a starting slash. So I'd have /org/wgt/base/mapping/Contact.hbm.xml. This is of course presuming that the mapping file is actually located on that path within the jar.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 2:47 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
the forward slash is not necessary. I'm sure if gaetmail looks around he/she will find that some minor detail has just been overlooked.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 5:05 pm 
Regular
Regular

Joined: Fri Sep 30, 2005 6:15 am
Posts: 50
Thanks for help!

Here is my (simplified) architecure of my webapp


WEB-INF
|
|-------config
| |----------hibernate.cfg.xml //shown in previous post
|
|-------lib
|----------data.jar //include .hbm.xml and .class


In the JAR "data.jar" I have my files "org/wgt/base/mapping/Contact.hbm.xml" and
"org/wgt/base/mapping/Contact.java"


is this king of architecture possible?

do you know if I could had also "hibernate.cfg.xml" in my jar?

TIA!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 5:07 pm 
Regular
Regular

Joined: Fri Sep 30, 2005 6:15 am
Posts: 50
My directory tree is more readable like this..sorry

Code:
WEB-INF
     |
     |-------config
     |          |----------hibernate.cfg.xml //shown in previous post
     |
     |-------lib
                |----------data.jar //include .hbm.xml and .class


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 5:35 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
it will work if you put hibernate.cfg.xml at the root of data.jar ... rememeber that means to use the no args Configuration.configure() call instead of Configuration.configure("some/path/hibernate.cfg.xml") .

if that doesn't work, you may be mistaken about the contents of the jar file.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 5:45 pm 
Regular
Regular

Joined: Fri Sep 30, 2005 6:15 am
Posts: 50
Thanks for reply,

but can I keep my *.hbm.xml and my *.class in their respective packages? or do I have to have th *.hbm.xml at the root too?

Thans dennis!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 5:55 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
it is better practice to keep them where they are. however, if want to put the .hbm files in the base, you would have to adjust the appropriate mapping element in hibernate.cfg.xml file.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 6:42 am 
Regular
Regular

Joined: Fri Sep 30, 2005 6:15 am
Posts: 50
Thanks everybody for your help!

I redone a complete test and it's now working...I do not know the mistake I did in previous test..maybe a wrong path...

However I've decided to keep only the hibernate.cfg.xml outside of my jar because it has database configuration that may change between wep abb where hibernate is use.
But My hibernateFilter and hibernateUtil are also in this jar....like this I have just very few things to do now to integrate hibernate in my web app!

THANKS AGAIN!

PROBLEM SOLVED!


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