Home > OS >  Primary and foreign key implementation Java and Android Room
Primary and foreign key implementation Java and Android Room

Time:11-20

This is my first time asking a question here in StackOverflow so forgive me if I am not asking the question right or a certain way.

I have two child classes (PerformanceAssessment and ObjectiveAssessment) from parent class Assessment. I was able to successfully do downcasting for the polymorphism part requirement of my school project, and I was able to save to their appropriate databases both instances of parent and child after downcasting (I have an assessment_table, performance_assessments, and objective_assessments table). However, I am now having Android Room database issues. I realized that I need to implement foreign keys to do the CRUD operations properly. How do I tweak my parent and child classes code and add proper annotations for implementing foreign and primary keys correctly? I need to have an autogenerated primary key for each class: parent (Assessment) and both children (PerformanceAssessment and ObjectiveAssessment). But I also need to utilize the children's primary key as a foreign key for the parent's databases so that when I delete an instance of Performance/Objective assessments, I can also delete the Assessment instance when I am downcasting. I found very little helpful information regarding this. Thanks in advance.

I am getting these errors right now:

enter image description here

enter image description here

  • See how PerformanceAssessment with an assessment_id of 2 (it's unqiue row identifier) has an assessment_reference value of 103. This says the the Assessment with an assessment_id of 103 is the parent (or this PerformanceAssessment relates(belongs) to the Assessment that has an assessment_id of 103).

enter image description here

  • Related