gpt4 book ai didi

grails - 服务层和交易

转载 作者:行者123 更新时间:2023-12-02 15:29:56 25 4
gpt4 key购买 nike

我有2个DB,正在使用的服务方法从DB 1中传入对象,并尝试从第2个DB中检索和处理hasMany项目。当我将流程包装在.withTransaction中时,该方法有效。

def buildApoMap( Apo pApo ) {           
def lResults = [:]
Apo.withTransaction() {
if ( pApo ) {
lResults.apo = [ id: pApo.id, apoId: pApo.apoId,
accountName: pApo.account?.accountName,
subProgram: [ id: pApo.subProgram?.id, name: pApo.subProgram?.name],
eventCount: pApo.events?.toList().size ]

if ( pApo.events ) {
lResults.apo.events = pApo.events.collect { lEvent ->
[id: lEvent.id, eventReferenceId: lEvent.eventReferenceId,
sellingMethod: lEvent.sellingMethod?.toString(),
accountCommissionMethod: lEvent.accountCommissionMethod]
}
}
}
}
return lResults
}

当我宣布
 static transactional = true

该方法失败,并显示以下错误消息
ERROR 2014-01-10 08:44:48,084 [JDBCExceptionReporter] [http-bio-8080-exec-4] [unknown 8:44:47 AM|] - Connection is closed.
ERROR 2014-01-10 08:44:48,091 [ApoRestController] [http-bio-8080-exec-4] [unknown 8:44:47 AM|] - Unexpected exception while processing Rest request to search for APOs.
org.hibernate.exception.GenericJDBCException: could not initialize a collection: [com.company.Apo.events#7]
at com.company.ApoService$$EOSYMFqe.buildApoMap(ApoService.groovy:240)
at com.company.ApoRestController$_search_closure2.doCall(ApoRestController.groovy:78)
at com.company.ApoRestController.search(ApoRestController.groovy:77)
at org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:65)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.sql.SQLException: Connection is closed.
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.checkOpen(PoolingDataSource.java:185)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:312)
... 7 more

有任何想法吗?我们会做很多事情。不必将每个方法包装在自己的事务中。

最佳答案

我认为您需要使用atomikos插件(http://www.grails.org/plugin/atomikos)之类的东西来支持跨多个数据库的事务。

关于grails - 服务层和交易,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21047699/

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