Buggy code:
} Calendar insertTime = Calendar . getInstance ( ) ; FieldWorker collectedBy = fieldWorkerService . getByUuid ( individualForm . getFieldWorkerUuid ( ) ) ; if ( null == collectedBy ) { cv . addViolations ( ( ( ( ConstraintViolations . INVALID_FIELD_WORKER_EXT_ID ) + ":<seq2seq4repair_space>IndividualForm<seq2seq4repair_space>has<seq2seq4repair_space>a<seq2seq4repair_space>nonexistent<seq2seq4repair_space>field<seq2seq4repair_space>worker<seq2seq4repair_space>id<seq2seq4repair_space>-<seq2seq4repair_space>" ) + ( individualForm . getFieldWorkerExtId ( ) ) ) ) ; String errorDataPayload = createDTOPayload ( individualForm ) ; ErrorLog error = ErrorLogUtil . generateErrorLog ( UNASSIGNED , errorDataPayload , null , IndividualForm . class . getSimpleName ( ) , null , UNRESOLVED_ERROR_STATUS , cv . getViolations ( ) ) ; errorService . logError ( error ) ; return requestError ( cv ) ; } Location location ; try { location = locationService . getByUuid ( individualForm . getHouseholdUuid ( ) ) ; if ( null == location ) { cv . addViolations ( ( ( ( ConstraintViolations . INVALID_LOCATION_EXT_ID ) + ":<seq2seq4repair_space>IndividualForm<seq2seq4repair_space>has<seq2seq4repair_space>a<seq2seq4repair_space>nonexistent<seq2seq4repair_space>location<seq2seq4repair_space>id<seq2seq4repair_space>-" ) + ( individualForm . getHouseholdExtId ( ) ) ) ) ; String errorDataPayload = createDTOPayload ( individualForm ) ; ErrorLog error = ErrorLogUtil . generateErrorLog ( UNASSIGNED , errorDataPayload , null , IndividualForm . class . getSimpleName ( ) , collectedBy , UNRESOLVED_ERROR_STATUS , cv . getViolations ( ) ) ; errorService . logError ( error ) ; return requestError ( cv ) ; } } catch ( Exception e ) { return requestError ( ( "Error<seq2seq4repair_space>getting<seq2seq4repair_space>location:<seq2seq4repair_space>" + ( e . getMessage ( ) ) ) ) ; } try { createOrSaveLocation ( location ) ; } catch ( ConstraintViolations e ) { String errorDataPayload = createDTOPayload ( individualForm ) ; ErrorLog error = ErrorLogUtil . generateErrorLog ( UNASSIGNED , errorDataPayload , null , IndividualForm . class . getSimpleName ( ) , collectedBy , UNRESOLVED_ERROR_STATUS , e . getViolations ( ) ) ; errorService . logError ( error ) ; return requestError ( e ) ; } catch ( SQLException e ) { return serverError ( ( "SQL<seq2seq4repair_space>Error<seq2seq4repair_space>updating<seq2seq4repair_space>or<seq2seq4repair_space>saving<seq2seq4repair_space>location:<seq2seq4repair_space>" + ( e . getMessage ( ) ) ) ) ; } catch ( Exception e ) { return serverError ( ( "General<seq2seq4repair_space>Error<seq2seq4repair_space>updating<seq2seq4repair_space>or<seq2seq4repair_space>saving<seq2seq4repair_space>location:<seq2seq4repair_space>" + ( e . getMessage ( ) ) ) ) ; } Individual individual ; try { individual = findOrMakeIndividual ( individualForm , collectedBy , insertTime , cv ) ; if ( cv . hasViolations ( ) ) { String errorDataPayload = createDTOPayload ( individualForm ) ; ErrorLog error = ErrorLogUtil . generateErrorLog ( UNASSIGNED , errorDataPayload , null , IndividualForm . class . getSimpleName ( ) , collectedBy , UNRESOLVED_ERROR_STATUS , cv . getViolations ( ) ) ; errorService . logError ( error ) ; return requestError ( cv ) ; } } catch ( Exception e ) { return requestError ( ( "Error<seq2seq4repair_space>finding<seq2seq4repair_space>or<seq2seq4repair_space>creating<seq2seq4repair_space>individual:<seq2seq4repair_space>" + ( e . getMessage ( ) ) ) ) ; } findOrMakeResidency ( individual , location , collectionTime , insertTime , collectedBy ) ; try { createOrSaveIndividual ( individual ) ; } catch ( ConstraintViolations e ) { String errorDataPayload = createDTOPayload ( individualForm ) ; ErrorLog error = ErrorLogUtil . generateErrorLog ( UNASSIGNED , errorDataPayload , null , IndividualForm . class . getSimpleName ( ) , collectedBy , UNRESOLVED_ERROR_STATUS , e . getViolations ( ) ) ; errorService . logError ( error ) ; return requestError ( e ) ; } catch ( SQLException e ) { return serverError ( ( "SQL<seq2seq4repair_space>Error<seq2seq4repair_space>updating<seq2seq4repair_space>or<seq2seq4repair_space>saving<seq2seq4repair_space>individual:<seq2seq4repair_space>" + ( e . getMessage ( ) ) ) ) ; } catch ( Exception e ) { return serverError ( ( "General<seq2seq4repair_space>Error<seq2seq4repair_space>updating<seq2seq4repair_space>or<seq2seq4repair_space>saving<seq2seq4repair_space>individual:<seq2seq4repair_space>" + ( e . getMessage ( ) ) ) ) ; } SocialGroup socialGroup ; if ( individualForm . getIndividualRelationshipToHeadOfHousehold ( ) . equals ( IndividualFormResource . HEAD_OF_HOUSEHOLD_SELF ) ) { socialGroup = findOrMakeSocialGroup ( individualForm . getSocialgroupUuid ( ) , location , individual , insertTime , collectedBy ) ; location . setLocationName ( individual . getLastName ( ) ) ; } else { <START_BUG> socialGroup = socialGroupService . getByUuid ( individualForm . getHouseholdUuid ( ) ) ; <END_BUG> } findOrMakeRelationship ( individual , socialGroup . getGroupHead ( ) , collectedBy , collectionTime , insertTime , individualForm ) ; try { createOrSaveSocialGroup ( socialGroup ) ; } catch ( ConstraintViolations e ) { String errorDataPayload = createDTOPayload ( individualForm ) ; ErrorLog error = ErrorLogUtil . generateErrorLog ( UNASSIGNED , errorDataPayload , null , IndividualForm . class . getSimpleName ( ) , collectedBy , UNRESOLVED_ERROR_STATUS , e . getViolations ( ) ) ; errorService . logError ( error ) ; return requestError ( e ) ; } catch ( SQLException e ) { return serverError ( ( "SQL<seq2seq4repair_space>Error<seq2seq4repair_space>updating<seq2seq4repair_space>or<seq2seq4repair_space>saving<seq2seq4repair_space>socialGroup:<seq2seq4repair_space>" + ( e . getMessage ( ) ) ) ) ; } catch ( Exception e ) { return serverError ( ( "General<seq2seq4repair_space>Error<seq2seq4repair_space>updating<seq2seq4repair_space>or<seq2seq4repair_space>saving<seq2seq4repair_space>socialGroup:<seq2seq4repair_space>" + ( e . getMessage ( ) ) ) ) ; } Membership membership = findOrMakeMembership ( individual , socialGroup , collectedBy , collectionTime , insertTime , individualForm ) ; try { entityService . create ( membership ) ; } catch ( ConstraintViolations constraintViolations ) { return serverError ( ( "ConstraintViolations<seq2seq4repair_space>saving<seq2seq4repair_space>membership:<seq2seq4repair_space>" + ( constraintViolations . getMessage ( ) ) ) ) ; } catch ( SQLException e ) { return serverError ( ( "SQL<seq2seq4repair_space>Error<seq2seq4repair_space>updating<seq2seq4repair_space>or<seq2seq4repair_space>saving<seq2seq4repair_space>membership:<seq2seq4repair_space>" + ( e . getMessage ( ) ) ) ) ; } return new ResponseEntity < IndividualForm > ( individualForm , HttpStatus . CREATED ) ; } private Individual findOrMakeIndividual ( IndividualForm individualForm , FieldWorker collectedBy , Calendar insertTime , ConstraintViolations cv ) throws Exception { } private void copyFormDataToIndividual ( IndividualForm individualForm , Individual individual ) throws Exception { } private Individual makeUnknownParent ( String gender ) { } private static Calendar getDateInPast ( ) { } private SocialGroup findOrMakeSocialGroup ( String socialGroupUuid , Location location , Individual head , Calendar insertTime , FieldWorker collectedBy ) { } private Residency findOrMakeResidency ( Individual individual , Location location , Calendar collectionTime , Calendar insertTime , FieldWorker collectedBy ) { } private Membership findOrMakeMembership ( Individual individual , SocialGroup socialGroup , FieldWorker collectedBy , Calendar collectionTime , Calendar insertTime , IndividualForm individualForm ) { }

Fix:
socialGroup = socialGroupService . getByUuid ( individualForm . getSocialgroupUuid ( ) ) ;