-->
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.  [ 3 posts ] 
Author Message
 Post subject: location of hibernate.cfg.xml in a war file with jars
PostPosted: Thu May 26, 2005 8:05 pm 
Newbie

Joined: Mon May 10, 2004 2:28 pm
Posts: 10
Location: Seattle, WA
I have a deployment question when using Hibernate within a war file. I have my mapping files and classes (and java files in fact) in a jar which is included in the WEB-INF/lib directory. I also have a hibernate.cfg.xml file in the WEB-INF/classes directory (sample):

Code:
<hibernate-configuration>
    <session-factory name="foo">

        <mapping resource="/com/real/common/cmsdata/au/Bandwidth.hbm.xml"/>
        <mapping resource="/com/real/common/cmsdata/au/CategoryXmlLayout.hbm.xml"/>
...
...


When the code tries to configure the SessionFactory:

Code:
        Properties hibernateProperties = new Properties();
        try {
        [b]// I have stepped through this and its finding the properties fine[/b]
            String propertiesFile = config.getProperty("hibernate-properties", "hibernate.properties");
            InputStream is = getEbiContext().getContentClient().openStream("conf/" + propertiesFile);
            if (null != is) {
                hibernateProperties.load(is);
            }
        }
        catch (IOException e1) {
            throw new EbiException("IO Exception encountered while reading Hibernate Properties.", e1);
        }
       
        Configuration cfg = new Configuration();
        cfg.setProperties(hibernateProperties);

        try {
            cfg.configure();
            cSessionFactory = cfg.buildSessionFactory();
        } catch (HibernateException e) {
            e.printStackTrace();
            throw e;
        }


I get the following exception:

Code:
2005-05-26 16:58:02,363 WARN applog.class com.real.common.cmsdata.HibernateManag
erContextFactory - Passed a null config object into start init.
org.hibernate.MappingException: Resource: /com/real/common/cmsdata/au/Bandwidth.
hbm.xml not found
        at org.hibernate.cfg.Configuration.addResource(Configuration.java:443)
        at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.jav
a:1312)
        at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.jav
a:1284)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1266)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1233)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1161)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1147)



Any suggestions as to how I can (if I can) have my mappings and classes in a jar file and the hibernate.cfg.xml file outside of that jar would be greatly appreciated.

thanks,

Ian.

Hibernate version:

3.0.1

I am using Tomcat 4.1


[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 9:10 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
Try removing the leading slash from your paths.

Code:
<mapping resource="com/real/common/cmsdata/au/Bandwidth.hbm.xml"/>


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 9:15 pm 
Newbie

Joined: Mon May 10, 2004 2:28 pm
Posts: 10
Location: Seattle, WA
Thanks, that did it.


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