gpt4 book ai didi

java - Hibernate Multi-Tenancy 测试因 NPE 失败

转载 作者:行者123 更新时间:2023-11-30 03:27:38 26 4
gpt4 key购买 nike

我正在使用基于模式的 Multi-Tenancy ,为 MultiTenantConnectionProvider 和 CurrentTenantIdentifierResolver 提供实现。尝试为单个租户获取 hibernate session 失败并出现 NPE。查看hibernate的源代码,似乎JDBCServicesImpl在else block 中将connectionProvider初始化为null

private JdbcConnectionAccess buildJdbcConnectionAccess(Map configValues) {
final MultiTenancyStrategy multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configValues );

if ( MultiTenancyStrategy.NONE == multiTenancyStrategy ) {
connectionProvider = serviceRegistry.getService( ConnectionProvider.class );
return new ConnectionProviderJdbcConnectionAccess( connectionProvider );
}
else {
connectionProvider = null;
final MultiTenantConnectionProvider multiTenantConnectionProvider = serviceRegistry.getService( MultiTenantConnectionProvider.class );
return new MultiTenantConnectionProviderJdbcConnectionAccess( multiTenantConnectionProvider );
}
}

请在此处找到此测试用例 - http://pastebin.com/7Mt9wtHt及其堆栈跟踪 - http://pastebin.com/8ygAu7eh

我错过了一些基本的东西吗?

最佳答案

好吧,在查看源代码一段时间后。 Hibernate(目前)不支持模式导出。这是取自他们的documentation .

Currently schema export will not really work with multi-tenancy. That may not change

因此,就您的情况而言,解决方法是删除此行

config.getProperties().put(AvailableSettings.HBM2DDL_AUTO, "validate");

关于java - Hibernate Multi-Tenancy 测试因 NPE 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29814744/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com