java 何时使用 hibernate.connection.provider_class

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6372291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 15:38:38  来源:igfitidea点击:

when to use hibernate.connection.provider_class

javahibernate

提问by Ravi Parekh

When should I use hibernate.connection.provider_class? I am a little confused between it and 'hibernate.connection.diver_class'.

我应该什么时候使用hibernate.connection.provider_class?我对它和 'hibernate.connection.diver_class' 有点困惑。

provider_class might be useful for connection pool

provider_class 可能对连接池有用

is there any other purpose where we can use provider_class?

我们可以使用 provider_class 有什么其他目的吗?

采纳答案by Martin Peters

Another use for connection provider is to uphold sessions over time, this is especially true with the combination of mysql + hibernate. If you don't have a properly configured connection provider that handles timeouts from mysql, you're likely to loose your connection to the database sooner or later if you have periods of inactivity.

连接提供程序的另一个用途是随着时间的推移维持会话,这对于 mysql + hibernate 的组合尤其如此。如果您没有正确配置的连接提供程序来处理来自 mysql 的超时,那么如果您有一段时间不活动,您迟早可能会失去与数据库的连接。

回答by Thomas W

ConnectionProvider is what you use to customize your strategy for obtaining connections. As well as connection pooling, it can be used to implement multi-tenancy databases.

ConnectionProvider 是您用来自定义获取连接的策略的工具。除了连接池之外,它还可以用于实现多租户数据库。

A brief run-thru:

一个简短的运行:

http://literatejava.com/hibernate/multi-tenancy-architecture-with-hibernate/

http://literatejava.com/hibernate/multi-tenancy-architecture-with-hibernate/

回答by joostschouten

The driver class is what it sais it is, what driver do you use to connect to your db. The connection provider class is class that can manage your connections for you and provide it to the session.

驱动程序类就是它所说的,您使用什么驱动程序连接到您的数据库。连接提供程序类是可以为您管理连接并将其提供给会话的类。

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

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

The connection provider class is usually used if you want to use connection pooling. eg: hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider.

如果要使用连接池,通常会使用连接提供程序类。例如:hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider。