Hibernate 4.2基于模式的多租户+ C3P0连接池

3
我正在运行一个使用Hibernate 4.2.0的Java应用程序(Java 1.7),我需要实现基于模式的多租户设置。 我使用了this示例来完成。 我的问题是我无法弄清楚如何创建连接提供程序。 示例使用以下内容:
    acmeProvider = ConnectionProviderBuilder.buildConnectionProvider("acme");
    jbossProvider = ConnectionProviderBuilder.buildConnectionProvider("jboss");
ConnectionProviderBuilder 仅用于测试。
我尝试使用以下内容:
    C3P0ConnectionProvider connectionProvider = new C3P0ConnectionProvider()
    {
        public boolean supportsAggressiveRelease()
        {
            return allowAggressiveRelease;
        }
    };
connectionProvider.configure(props);
这里的问题是C3P0ConnectionProvider具有空的serviceRegistry,导致NPE崩溃。

有人知道如何为每个租户创建ConnectionProvider吗?

谢谢,

Ronen


请问如何在使用Hibernate的多租户应用程序中管理连接池? - Optional
1个回答

0
尝试使用Properties添加数据源属性suggestion
DatasourceConnectionProviderImpl cp = new DatasourceConnectionProviderImpl();
cp.setDataSource(ds);
Properties p = new Properties();
// ...
cp.configure(p);

或者使用DriverManagerConnectionProviderImpl:

DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl() {
   public boolean supportsAggressiveRelease() {
     return allowAggressiveRelease;
   }
 };
 connectionProvider.configure( props );

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接