how to map HBM files dynamically in hibernate?
Hibernate开发者_如何学Python mapping files are either declared:
Programmatically when creating a Configuration
For example:
Configuration cfg = new Configuration() .addResource("Item.hbm.xml") .addResource("Bid.hbm.xml");
In an Hibernate XML configuration file
For example:
<!-- Database connection settings -->
<property name="connection.driver_class">${jdbc.driver}</property>
<property name="connection.url">${jdbc.url}</property>
<property name="connection.username">${jdbc.user}</property>
<property name="connection.password">${jdbc.password}</property>
...
<mapping resource="com/acme/Foo.hbm.xml"/>
<mapping resource="com/acme/Bar.hbm.xml"/>
...
In a Spring XML application context definition
For example:
product.hbm.xml hibernate.dialect=org.hibernate.dialect.HSQLDialect
But In my application, there are hundreds of hbm files. So, is there any ways like I will put all hbm files in same package and map that package with configuration file? Or any easy way to map all hbm files?
I would just list them all in a configuration file. This is a one time job and after that only new files are added to the list.
I had similar problem where I wanted to avoid listing all hbm files. My problem was little complex because hbm files were comming from different modules. If all your hbm files are coming from same module/jar then you can just add jar name like below
<mapping jar="/D:/Test/target/test-1.0.jar" />
and if you are using JPA and have persistence.xml then you could provide root folder path in persistence.xml file where all hbm files lies
<persistence-unit ...... >
<jar-file>file:/D:/Test/target/</jar-file>
精彩评论