Why can't I find primary concept for DiagnosisMetadata?

Version: Platform 1.11.5 (upgrading from 1.9.3)

I updated my openmrs installation 1.9.3 to the latest version 1.11.5.

Now, when trying to access a patient from the tile “Find patient record”, I am getting this error message:

java.lang.IllegalStateException: Couldn't find primary concept for DiagnosisMetadata which should be mapped as org.openmrs.module.emrapi:Diagnosis Concept Set

I noticed that the reference metadata module is not running, but when trying to start it I get an error that the module could not be started (without additional error details).

Checking the server log reveals these errors:

ERROR - JDBCExceptionReporter.logExceptions(234) |2016-02-19 15:43:58,693| 
Cannot delete or update a parent row: a foreign key constraint fails (`openmrs`.`concept`, CONSTRAINT `concept_classes` FOREIGN KEY (`class_id`) REFERENCES `concept_class` (`concept_class_id`))
ERROR - LoggingAdvice.invoke(135) |2016-02-19 15:43:58,707| An error occurred while executing this method.
Current user: admin
Error message: Could not execute JDBC batch update; SQL [delete from concept_class where concept_class_id=?]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

When I remove the constraint ‘concept_class’ from table concept the SQL is executed sucsessfully. However, the reference metadata module still does not start and now the following related warnings/errors are shown under server log:

WARN - AbstractTableMetaData.getDataTypeFactory(166) |2016-02-19 15:53:40,760| Potential problem found: The configured data type factory 'class org.dbunit.dataset.datatype.DefaultDataTypeFactory' might cause problems with the current database 'MySQL' (e.g. some datatypes may not be supported properly). In rare cases you might see this message because the list of supported database products is incomplete (list=[derby]). If so please request a java-class update via the forums.If you are using your own IDataTypeFactory extending DefaultDataTypeFactory, ensure that you override getValidDbProducts() to specify the supported database products.
WARN - ModuleUtil.refreshApplicationContext(879) |2016-02-19 15:53:40,793| Unable to invoke started() method on the module's activator
ERROR - CommonsLoggingOutput.error(75) |2016-02-19 15:53:40,881| Line=113 The content of element type "dwr" must match "(init?,allow?,signatures?)".
ERROR - CommonsLoggingOutput.error(75) |2016-02-19 15:53:40,882| Parameter mismatch parsing signatures section in dwr.xml on line: DWRAtlasService.disableAtlasModule()
ERROR - CommonsLoggingOutput.error(75) |2016-02-19 15:53:40,883| Parameter mismatch parsing signatures section in dwr.xml on line: DWRHtmlFormEntryService.checkIfLoggedIn()
ERROR - CommonsLoggingOutput.error(75) |2016-02-19 15:53:40,895| Parameter mismatch parsing signatures section in dwr.xml on line: DWREncounterService.findEncounters(String phrase, Integer patientId, boolean includeVoided)

When trying to access a patient now I am getting a ‘no encounter type with uuid’ error.

I checked my db encoding as suggested in this thread and checked that my openmrs db and all it’s tables have utf8 encoding:

I also tried restarting the server and using other versions of the reference metadata module (2.3, 2.1.1), but to no avail.

Did you follow the steps described here?

Thanks for your reply, Pascal. I actually followed all the steps listed on the upgrade wiki page and the upgrade procedure went through successfully. I have checked each point again and can confirm that all requirements are fulfilled. Could the problem be caused by the reference metadata module not running ? Whenever I attempt to start it, I am getting an error that it could not be started. Any suggestions on how to fix that ?

Yes, that could be the problem. What error is shown in the logs when you attempt to start the Reference Metadata module?

These errors are listed in the server log after trying to start the reference metadata module:

ERROR - JDBCExceptionReporter.logExceptions(234) |2016-02-19 15:43:58,693| 
Cannot delete or update a parent row: a foreign key constraint fails (`openmrs`.`concept`, CONSTRAINT `concept_classes` FOREIGN KEY (`class_id`) REFERENCES `concept_class` (`concept_class_id`))
ERROR - LoggingAdvice.invoke(135) |2016-02-19 15:43:58,707| An error occurred while executing this method.
Current user: admin
Error message: Could not execute JDBC batch update; SQL [delete from concept_class where concept_class_id=?]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

All modules I am using are from the openmrs-2.3.1 modules package provided on the openmrs website. I installed the modules by copying them to the bundledModules folder in the webapp directory.

@jevgeni, check if you have any of the openmrs tables that are not utf-8 encoded. I had a similar issue and changing all the tables that were not utf-8 encoded resolved the problem. I tested using openmrs platform 1.11.6 and reference application 2.3.1.