我正在尝试集成测试 Gorm 悲观锁,并使用多线程同时模拟来自许多服务器的访问,但在每个线程中我没有得到预期的结果。这是我的代码:
@Test
void testLockInBetweenCheck() {
def tid = IdocTidInfo.findByTid("AC10870D0E12504F3E88D575") //here tid is not null
withPool{
[1,2].eachParallel{ tids ->
IdocTidInfo.withTransaction{ tid ->
def t = IdocTidInfo.findByTid("AC10870D0E12504F3E88D575") // here is t is null
我不知道发生了什么,我认为我的 Hibernate sessionFactory 没有绑定(bind)到每个线程,并且 Domain.withTransaction 我应该工作,但它没有。
有什么帮助吗?
最佳答案
这与集成测试的Set Up方法有关,我在内存中引导数据。一旦我将其转移到 Bootstrap,线程的闭包就可以绑定(bind) hibernate session !无论如何,谢谢!!
关于hibernate - GORM GPARS 集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12377140/