views:

38

answers:

1

This is still a pending question. Hopefully, one day I'll get an answer. Thanks to all who replied.

My question is simple. How do I use ${catalina.home} or ${catalina.base} property inside a Hibernate XML configuration file?

Here's my sample configuration file:

<hibernate-configuration>
<session-factory>
    <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
    <property name="hbm2ddl.auto">update</property>
    <property name="show_sql">false</property>
    <property name="cache.use_second_level_cache">false</property>

    <mapping jar="/opt/tomcat/apache-tomcat-5.5.29/webapps/MyApp/WEB-INF/lib/MyHibernateMaps.jar" />
</session-factory>

My current configuration file is okay. But I would like to at least abstract away the tomcat location. Instead of using this:

<mapping jar="/opt/tomcat/apache-tomcat-5.5.29/webapps/MyApp/WEB-INF/lib/MyHibernateMaps.jar" />

I want to convert that to this:

<mapping jar="${catalina.base}/webapps/MyApp/WEB-INF/lib/MyHibernateMaps.jar" />

I tried doing that directly but I just got an error that the jar file is missing or cannot be found. I've Googled but to no avail.

The reason why I need to have a setup like this is because I deploy my apps in three machines. One is for the production. The other one is for development. And the last one is for localhost (at home). These three machines have tomcat installed on three different location.

So everytime I deploy my app I have to modify the line /opt/tomcat/apache-tomcat-5.5.29/ to match the tomcat location on the machine.

Any ideas?

Also, is it preferrable to use catalina.home or catalina.base? I'm only using one tomcat on the localhost. But on the development and production, we have two tomcats (on two different locations of course).

Thanks

By the way, this Hibernate configuration file is used inside a Spring XML config file:

<bean id="appSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
     <property name="dataSource">
    <ref local="appDataSource"/>
     </property>
     <property name="configLocation">
            <value>${hibernate.config}</value>
     </property>
</bean>
+1  A: 

You don't need this. Assuming a JAR is on the application classpath (and this is the case of JARs under the /WEB-INF/lib directory of a WAR), just use:

<mapping jar="myapp.jar" />
Pascal Thivent
Oh really. I never thought about that. Thanks for the reply. I will surely try that and report back here.
chris
I tried your suggestion with a local machine and development machine. However, it didn't work. I got the following error:Error creating bean with name 'appSessionFactory' defined in ServletContext resource [/WEB-INF/appConfig.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Could not read mapping documents from jar: MyApp.jar
chris
I forgot to take note that the hibernate configuration file is a property of a SessionFactory declared in a Spring XML configuration file.
chris
Pascal, I've just found an article from the web: http://www.developer.com/open/article.php/10930_3559931_3/Hibernate-Basics.htmYour solution is the same as that article. However, it appears it only works if it's not used in a Spring XML config file.
chris