Place Hibernate configuration in a different location

馋奶兔 提交于 2019-12-10 11:08:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!