I am new to Hibernate and when I am using transactions I met couple of questions. Previously, the situation is
@Transactional
Class A {
methodA1(){
DOs = fetchDOsFromDB();
methodA2(DOs);
}
methodA2(DOs){
ClassB.methodB1(DOs);
}
}
Class B{
@Transactional(propagation = Propagation.REQUIRES_NEW)
methodB1(DOs){
dealWithDOs();
}
}
But I found when the amount of DOs is huge, it will give connection is closed exception. So I am wondering if the root cause is I passed the DOs to methodB1 which bound with transaction in A and the transaction A can't be committed for a long time.
So this is the first question, I know @Transactional(propagation = Propagation.REQUIRES_NEW)
will make the outer transaction be suspended but what does suspend exactly mean? Does it have timeout?
And if I don't pass DOs
to classB
, instead, I do
methodA1(){
DOs = fetchDOsFromDB();
List<Integer> list = getIds(DOs);
methodA2(list);
}
methodA2(list){
ClassB.methodB1(list);
}
which means I am not relying on DOs
, will this help?
Is there any relationship between the commit of transaction A and the running result of transaction B? In other words, does the commit of transaction A need to wait for the completion of methodB1
?