Hibernate使用javax.sql.DataSource的一个实例 [英] Hibernate using an instance of javax.sql.DataSource

查看:337
本文介绍了Hibernate使用javax.sql.DataSource的一个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以配置Hibernate使用javax.sql.DataSource实例?



我的应用程序已经有一个javax.sql.DataSource的实例,而不是为hibernate重新配置数据库url,用户,密码,驱动等。 解决方案

如果数据源可用通过JNDI,你只需要设置配置文件的hibernate.connection.datasource属性--mtpettyp的答案证明了这一点。



如果你不在数据的环境中源代码来自JNDI,提供您自己的ConnectionProvider实现,并在构建会话工厂之前将其传递给Settings对象,或者在hibernate.connection.provider_class属性中指定其类名称。如果您向Settings提供实例,则可以实例化标准DatasourceConnectionProvider并将其提供给您的DataSource。


Is it possible to configure Hibernate to use a javax.sql.DataSource instance?

My application already has an instance of javax.sql.DataSource and I'd rather not re-configure the database url, user, password, driver etc just for hibernate.

解决方案

If the data source is available through JNDI, you just need to set the hibernate.connection.datasource property of the configuration - mtpettyp's answer demonstrates that.

If you're not in an environment where your data sources come from JNDI, provide your own ConnectionProvider implementation, and either pass it to the Settings object before building the session factory, or specify its class name in the hibernate.connection.provider_class property. If you provide an instance to Settings, you can probably instantiate the standard DatasourceConnectionProvider and give it your DataSource.

这篇关于Hibernate使用javax.sql.DataSource的一个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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