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]