将Hibernate配置放在不同的位置 [英] Place Hibernate configuration in a different location

查看:130
本文介绍了将Hibernate配置放在不同的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hibernate 配置文件(.hbm.xml)的理想位置是

  ... / tomcat / webapps / projectName / WEB-INF / classes / hbm 

但我想将这些配置设置放在不同的位置,例如

  / usr / local / properties / hibernate 



如果我将该配置文件放在该位置,如果我开始 Tomcat 然后它给我一个错误,加载配置说


hibernate.cfg.xml找不到



解决方案

配置 .cfg.xml 文件使用 Configuration.configure()而不是

code> Configuration.addDirectory()



另请参阅: b


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

解决方案

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:

这篇关于将Hibernate配置放在不同的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆