在Hibernate中以编程方式设置属性 [英] Setting properties programmatically in Hibernate

查看:104
本文介绍了在Hibernate中以编程方式设置属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确保所有属性都从hibernate.cfg.xml加载,然后以编程方式添加其他属性?我看到下面的代码片断,但它看起来像一个全新的配置,而不是现有的配置。

How can I ensure that all properties are loaded from hibernate.cfg.xml, then add additional properties programmatically? I saw the following code snippet but it looks like a completely new configuration, not an addition to an existing one.

Configuration c = new Configuration();
c.configure();

c.setProperty("hibernate.connection.username", "abc" );
c.setProperty("hibernate.connection.password", "defgh629154" ); 


推荐答案

您展示的代码段是您需要的。只需使用现有的配置,而不是创建一个新的配置。

The code snippet you showed is what you need. Just use your existing configuration instead of creating a new one.

如果不是你实例化配置(但是,例如,spring),你需要扩展创建它的类。

If it is not you who instantiates the configuration (but, for example, spring), you'd need to extend the class that creates it.

这篇关于在Hibernate中以编程方式设置属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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