如何使用hibernate.properties文件而不是hibernate.cfg.xml [英] How to use hibernate.properties file instead of hibernate.cfg.xml

查看:171
本文介绍了如何使用hibernate.properties文件而不是hibernate.cfg.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Hibernate连接到一个servlet的数据库。我已经阅读,我们可以使用hibernate.cfg.xml或hibernate.properties文件配置会话。对于我使用xml。现在,当我试图使用属性而不是xml它不工作。
这是说 hibernate.cfg.xml 没有找到。但是我没有提到使用xml文件和infact我删除了该xml文件。



请帮助我。
如果我做错了什么,请纠正我。

解决方案

从我从hibernate理解的最好的事情, do是定义 hibernate.cfg.xml 文件中的映射以及 hibernate.properties 中的其他配置。 / p>

另一种配置方法是在名为 hibernate.cfg.xml 的文件中指定完整配置。此文件可用于替换 hibernate.properties 文件,如果两者都存在,则覆盖属性。



当你必须调整Hibernate缓存时, hibernate.cfg.xml 也更方便。您可以选择使用hibernate.properties或 hibernate.cfg.xml 。两者都是等价的。



您可以在以下链接中了解更多信息:



http://docs.jboss.org/hibernate/core/3.3/ reference / en / html / session-configuration.html


I am trying to connect to DB in a servlet using Hibernate.I have read that we can use either hibernate.cfg.xml or hibernate.properties file for configuration of session.For me it worked with xml. Now when I am trying to use properties instead of xml its not working. It is saying that hibernate.cfg.xml not found.But nowhere I mentioned to use xml file and infact I have deleted that xml file.

Please Help me. And Please correct me if I am doing anything wrong.

解决方案

From what i understood from hibernate the best thing to do is to define the mapping in the hibernate.cfg.xml file and other configurations in the hibernate.properties.

An alternative approach to configuration is to specify a full configuration in a file named hibernate.cfg.xml. This file can be used as a replacement for the hibernate.properties file or, if both are present, to override properties.

The hibernate.cfg.xml is also more convenient once you have to tune the Hibernate cache. It is your choice to use either hibernate.properties or hibernate.cfg.xml. Both are equivalent.

You can read more about this in the following link:

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html

这篇关于如何使用hibernate.properties文件而不是hibernate.cfg.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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