Back Forum Reply New

Handling distributed hibernate mapping files

Hi,
Our application is a web one with multiple independent modules each of which are distributed as jar files. All these jars contain their own hibernate entities and their mapping XMLs. It also contains any spring configuration files which contains beans exposed by that module.

Our final app however is not a jar file. Its going to be a raw build containing all sources and resources under web root.

I take one module - a simple audit module to explain my problem. audit.jar ships with a audit-spring-context.xml file carrying a few beans.

My app Spring config looks as below :Code:

lt;beansgt;
lt;import resource=quot;db-context.xmlquot; /gt;
lt;import resource=quot;audit-spring-context.xmlquot; /gt;

lt;bean id=quot;sessionFactoryquot; class=quot;org..orm.hibernate3.LocalSessionFactoryBeanquot; gt;
lt;property name=quot;dataSourcequot;gt;lt;ref bean=quot;dataSourcequot;/gt;lt;/propertygt;

lt;property name=quot;mappingDirectoryLocationsquot;gt;
lt;listgt;
lt;valuegt;classpath:lt;/valuegt;
lt;/listgt;
lt;/propertygt;

lt;property name=quot;mappingJarLocationsquot;gt;
lt;listgt;
lt;valuegt;classpath:/shared/dist/effigent-audit.jarlt;/valuegt;
lt;/listgt;
lt;/propertygt;    .........      lt;/beangt;
I get exception on launch :Code:
Caused by: java.io.FileNotFoundException: class path resource [shared/dist/effigent-audit.jar] cannot be resolved to ucl because it does not exist
at org..core.io.ClassPathResource.getucl(ClassPathResource.java:157)
at org..core.io.ClassPathResource.getFile(ClassPathResource.java:169)
at org..orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:676)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:363)
How do i know what classpath Spring is using ? Can we change it dynamically ? Cant we access jar files at locations not in my classpath ?

Pl let me know how to go about in such a distributed hibernate entities scenario.

Thanks

If you are trying to access file that are not in the classpath through the classpath mechanism, obviously it will not work. Since you have a distributed locations I would advice you to use a custom class which can be configured to look into various locations (such as classpath, jars, JNDI for example) and the return the results as Resources.
Spring already provides plenty of ResourceLoader which you can simply configure with the appropriate patterns and return them to the factory bean.
¥
Back Forum Reply New