vendredi 10 avril 2015

Specify a regular expression for LocalSessionFactoryBean mappingLocations

In my application, I have specified the below configuration for automatically picking up all the HBM files under a specific folder in the classpath.



<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="mappingLocations">
<list>
<value>classpath:hbms/**/*.hbm.xml</value>
</list>
</property>
</bean>


Now, for a new requirement, there is a need to create multiple HBM files with named queries specific to database. The HBM file names will be of the pattern test.DB.hbm.xml. For example, test.oracle.hbm.xml and test.db2.hbm.xml. In addition to these, there are the old regular HBM files (for mapping to tables) with name format as table1.hbm.xml, table2.hbm.xml, etc. also present in the same folder.


Using the above pattern, hibernate loading of the files fails, due to duplicate named queries in the new hbm files (since the name would be same in all such files).


The requirement is now to load the regular HBM files and also the DB specific HBM files. Is it possible to achieve this by using a regular expression as below?



classpath:hbms/**/*.(.${dbType}).hbm.xml


In the above example, dbType is available as a Spring environment property. My attempt with these changes resulted in none of the HBM files being loaded (including the old ones).


Am I doing something wrong with the regular expression or is it not possible to do this via XML configuration?


Thank you.


Aucun commentaire:

Enregistrer un commentaire