My upper service class is injected with several services as below:
@Service
@Slf4j
public class LoadService implements ILoadService {
@Autowired LoadService1 loadService1;
@Autowired LoadService2 loadService2;
@Autowired LoadService3 loadService3;
@Autowired GeneralService generalService;
@Override
public int load123() {
loadService1.load();
loadService2.load();
loadService3.load();
}
While loadService2.load()
was executing, I got errors
InvalidDataAccessApiUsageException: detached entity passed to persist: class1
where class2 should be persisted, which has one-to-one relation to class1. and
InvalidDataAccessApiUsageException: detached entity passed to persist .LazyInitializationException: failed to lazily initialize a collection of role
where class3 has a many-to-one relation to class1.
(It was also wired that all load functions from loadServices are almosst the same, but the error only occurred in loadService2)
I understand the error in this way, that the proxies were somehow closed, I found a solution was simply adding @Transactinal
upon the upper Service class. Which was not my intention, because I still want to have part of the data even when error occurred.
Does anybody know how to keep the proxies active without setting transactinal! Thanks a lot!