SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:A one-to-one between patient and doctor means that every patient has his/her own dedicated doctor that does not have any other patients. I doubt that's correct. I therefore agree with Himai that a many-to-one would be better.
That said, if you ever have a one-to-one, it's very uncommon to have the bidirectional relationship at a database level too. The logical one-to-one is mostly actually a many-to-one in the database, with a unique constraint that the many side is limited to just one. Otherwise the two records get really tightly coupled, which has several complications. For instance, on at least one side the foreign key cannot be NULL, because a record has to be created first before its primary key can be used for a foreign key - and you simply cannot create two records at the same time.
Often the most important part of the news is what they didn't tell.
Tim Holloway wrote:It is possible to add 2 related records at the same time in the same transaction, although if you're using auto-generated keys, that means that you have to first get the doctor record saved and populated with its primary key. The patient Entity does not have the doctor ID in it, because this is an ORM and it references a Doctor object which, again, we just generated an ID for, so at that point, the patient record can be saved. The doctor Entity contains a Patient Collection property managing the reverse relationship, so you also have to add the Patient there and re-save the updated Doctor.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Often the most important part of the news is what they didn't tell.
obaid abbassi wrote:Now I want to get dId in patient table and pId in Doctor table vice versa
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:I was referring to this:
obaid abbassi wrote:Now I want to get dId in patient table and pId in Doctor table vice versa
Because yes, you are absolutely right. I'd do it the way you described it.
Often the most important part of the news is what they didn't tell.
Often the most important part of the news is what they didn't tell.
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|