I have a service class the injects two JpaRepository classes: organizationRepository and stateRepository. In the service method I need to perform two transactions:
@Override
@Transactional
public Status createOrganization(@ResponseBody Organization organization) throws Exception {
Organization savedOrg = organizationRepository.save(organization);
int id = savedOrg.getOrgId();
State state = new State();
state.setOrgId(id);
state.setCode("MD");
State savedState = stateRepository.save(state);
.
.
.
This code isn't working and throwing a transaction error on my server. I also tried a saveAndFlush on the organizationRepository before trying to call the subsequent save for stateRepository. I realize I could also set the propagation properties but that didn't fix it either. The first save transaction always executes, but the second keeps failing. What can I do to solve?