0

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?

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
tblack06
  • 35
  • 2
  • 9
  • I think people will need to take a look on how have you implemented the save() method in both repository classes – Leo Jun 04 '16 at 02:01
  • 1
    *"... but the second keeps failing"* - Error message? Stacktrace? You need to provide the relevant info if you want help that goes to the specifics of your problem. – Stephen C Jun 04 '16 at 02:12

0 Answers0