A better option than defining each mapping resource using the mappingResources property of LocalSessionFactoryBean is using mappingDirectoryLocations with something like the following, only needed once for all the system.
<bean id="sessionFactory"> <property name="dataSource"> <ref bean="dataSource"> </ref> <property name="mappingDirectoryLocations"> <list> <value>net/sf/oness</value> </list> </property> <property name="hibernateProperties"> <ref bean="hibernateProperties"> </ref> </property> </property> </bean>
But be careful, this doesn’t allow you to use classpath locations, they have to be in the filesystem. AFAIK there’s no way to use all mapping files in the classpath under some package, that would be the best solution, e.g. I wanna use all *.hbm.xml in the classpath under net/sf/oness
The fact that you can’t use classpath hurts a lot.
The current solution doen’t work when doing war deployments under any os etc…
Actually you can specify a classpath location for your mapping files using classpath: . Here is a snip from my applicationContext file:
classpath:/foo/model
Works like a charm. Not sure where I first came across this.
CP
Try it deeply, it works ONLY when the classpath refers to files in the filesystem, not when they are in jars.
Yep, there is no way to ‘scan’ the classpath for resources or classes if it aint in the filesystem form.
That’s too bad since getting an index out of a ZipFile/JarFile is easy…