Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 春季社会及文化事务;JPA-具有指向同一数据库的两个数据源_Java_Jpa_Spring Social - Fatal编程技术网

Java 春季社会及文化事务;JPA-具有指向同一数据库的两个数据源

Java 春季社会及文化事务;JPA-具有指向同一数据库的两个数据源,java,jpa,spring-social,Java,Jpa,Spring Social,我目前正在开发一个Java应用程序,它使用SpringSocial与Twitter进行通信。该应用程序使用Spring数据(JPA)在本地管理用户 当我在Twitter上授权访问并且Twitter向OAuth1回调URL发出请求时,我的应用程序阻塞,我在日志文件中看到以下内容(我缩短了stacktrace): 经过一些研究,我相信我基本上看到了这里描述的问题: 出于某种原因,Spring Social core使用JdbcUsersConnectionRepository这一事实并不适合我的J

我目前正在开发一个Java应用程序,它使用SpringSocial与Twitter进行通信。该应用程序使用Spring数据(JPA)在本地管理用户

当我在Twitter上授权访问并且Twitter向OAuth1回调URL发出请求时,我的应用程序阻塞,我在日志文件中看到以下内容(我缩短了stacktrace):

经过一些研究,我相信我基本上看到了这里描述的问题:

出于某种原因,Spring Social core使用JdbcUsersConnectionRepository这一事实并不适合我的JPA设置。我知道有一个插件可用;然而,我决定试验数据源配置,创建了两个基本相同的数据源bean配置(名称不同),并将一个绑定到Spring Social,另一个绑定到我的entity manager配置


通过此设置,上述错误消失,我可以看到我的Twitter用户连接被持久化到数据库。我的问题是:这样做是有效的解决方案吗?还有哪些场景需要重复的数据源?另一方面-使用这种配置可能会产生什么影响?

此解决方案的缺点是需要减少连接池的最大容量

示例:假设您有一个连接池,其中最多有30个连接。现在,您需要为Spring Social添加另一个数据源。我假设您的每个用户将同时使用2个数据源。因此,您需要2个连接池,每个池中最多有15个连接。现在达到极限会容易得多

ERROR 2013-08-18 16:05:09,511 http-bio-8080-exec-44]  org.springframework.transaction.interceptor.TransactionInterceptor  [TransactionAspectSupport.completeTransactionAfterThrowing
(): "Application exception overridden by rollback exception"]
org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [insert into UserConnection (userId, providerId, providerUserId, ra
nk, displayName, profileUrl, imageUrl, accessToken, secret, refreshToken, expireTime) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; SQL state [null]; error code [0]; You can't operate 
on a closed Connection!!!; nested exception is java.sql.SQLException: You can't operate on a closed Connection!!!
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:603)
...
Caused by: java.sql.SQLException: You can't operate on a closed Connection!!!
        at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
        at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
        at com.mchange.v2.c3p0.impl.NewProxyConnection.prepareStatement(NewProxyConnection.java:171)
        at org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator.createPreparedStatement(JdbcTemplate.java:1438)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:581)
        ... 94 more
Caused by: java.lang.NullPointerException
        at com.mchange.v2.c3p0.impl.NewProxyConnection.prepareStatement(NewProxyConnection.java:135)
        ... 96 more
[WARN 2013-08-18 16:05:09,513 http-bio-8080-exec-44]  org.springframework.social.connect.web.ConnectController  [ConnectController.oauth1Callback(): "Exception while handling OAuth1 callback (Could not roll back JPA transaction; nested exception is javax.persistence.PersistenceException: unexpected error when rollbacking). Redirecting to twitter connection status page."]