问题
The ideal place for Hibernate configuration files (.hbm.xml) is
.../tomcat/webapps/projectName/WEB-INF/classes/hbm
But I want to place those configurations settings in a different location, say
/usr/local/properties/hibernate
How can I do that?
If I place that configuration files in that location and if I start Tomcat then it gives me an error on loading that configurations saying
hibernate.cfg.xml not found
回答1:
To configure location of .cfg.xml
file use Configuration.configure(File)
instead of Configuration.configure()
when creating SessionFactory
.
To configure location of .hbm.xml
files use Configuration.addDirectory()
.
See also:
- Configuration javadoc
来源:https://stackoverflow.com/questions/9108082/place-hibernate-configuration-in-a-different-location