Sal*_*mad 13 java xml database hibernate properties
我正在尝试使用Hibernate连接到servlet中的数据库.我已经读过我们可以使用hibernate.cfg.xml或hibernate.properties文件来配置session.For我使用xml.现在,当我尝试使用属性而不是xml时,它无法正常工作.这是说没有找到hibernate.cfg.xml .但是我提到使用xml文件并且事实上我已经删除了那个xml文件.
请帮我.如果我做错了,请纠正我.
小智 11
此代码默认调用hibernate.cfg.xml:
Configuration configuration = new Configuration().configure();
Run Code Online (Sandbox Code Playgroud)
默认情况下,此代码将调用hibernate.properties:
Configuration configuration = new Configuration();
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你.
从我对hibernate的理解,最好的办法是定义hibernate.cfg.xml
文件中的映射和其他配置hibernate.properties
.
另一种配置方法是在名为的文件中指定完整配置hibernate.cfg.xml
.此文件可用作文件的替代hibernate.properties
,如果两者都存在,则可用于覆盖属性.
hibernate.cfg.xml
一旦你必须调整Hibernate缓存,这也更方便.您可以选择使用hibernate.properties或hibernate.cfg.xml
.两者都是等价的.
您可以在以下链接中阅读有关此内容的更多信息:
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html
归档时间: |
|
查看次数: |
41231 次 |
最近记录: |