Review of extending cohort_member table with new columns

The referential integrity issue has to do with test data and not the query, you might want to make sure all existing cohort test data has been updated to match thew new structure. One of the primary benefits of an ORM tool like hibernate is to keep the DAO as DB agnostic as possible and this is why I’d prefer to use Restrictions.

These are the changes I made to the test data.

  <cohort cohort_id="1" name="Example Cohort" description="First cohort that is now voided" creator="1" date_created="2005-01-01 00:00:00.0" voided="true" voided_by="1" date_voided="2005-01-01 00:00:00.0" void_reason="This is voided" uuid="h9a9m0i6-15e6-467c-9d4b-mbi7teu9lf0f"/>
  <cohort cohort_id="2" name="Example Cohort" description="Second cohort that has not been voided" creator="1" date_created="2005-01-01 00:00:00.0" voided="false"/>
  <cohort_member cohort_member_id="1" cohort_id="1" patient_id="2" start_date="2016-01-01 00:00:00.0" creator="1"/>
  <cohort_member cohort_member_id="2" cohort_id="2" patient_id="6" start_date="2016-01-01 00:00:00.0" creator="1"/>

I’m checking how to work with Hibernate’s Criteria Queries, this is what I have come up with:

public List<Cohort> getCohortsContainingPatientId(Patient patient) throws DAOException {
    List<Cohort> cohorts = sessionFactory.getCurrentSession().createCriteria(Cohort.class)
	.createAlias("members", "m")
	.add(Restrictions.eq("m.patientId", patient))
    return cohorts;

Yet, I get the same error:

insert into cohort_member (cohort_member_id, cohort_id, patient_id, start_date, end_date, creator) values (null, ?, ?, ?, ?, ?) [23506-187]

As I mentioned earlier the referential integrity error has nothing to do with your query, there is more dataset files that you need to update, do a file search for xml test data files that contain ‘cohort’ in the file name, you can also look at the dataset files that are defined and executed within the same the class that contains that test.

Oh, I just made changes to this particular xml file: CohortServiceTest-cohort.xml. I will find if there are other datasets and update them. Will report back soon. Thanks.

Make sure that all the referenced patient_ids exist, I see in one of your test data files you reference patient_id 1 but I doubt if that patient exists

It was exactly that. I found more patient test data in the standardTestDataset.xml file and it wasn’t present there. Now all the tests passes successfully. Thank you very much for the help.

Now all the tests pass. I have incorporated all the changes as per your suggestions. How do I approach with the git commit? I believe adding a new commit should automatically update the pull request?

Yes, when you commit to the same branch and push the commit(s), github will update the PR.