I'm trying to map to an existing datamodel for an older product we are migrating to Java.
I have tried ever way to map this collection over the last few days with no success.
Code:
----------------------- ------------------------ -----------------------
| Person | | Phone_Nums | | Business |
----------------------- ------------------------ -----------------------
| Person_Id (PK) | | Phone-Nums_Id (CK) | | Business_Id (PK) |
| F_Name | | Order (CK) | ---- | Name |
| L_Name | ---- | Number | | Phone_Nums_Id (FK)|
| AGE | | Comment | -----------------------
| Phone_Nums_Id (FK) | ------------------------
-----------------------
Person and Business each have a collection of phone nums hanging off of them however there is no junction table. One part of a composite key (the Phone_Nums_Id) from the phone nums is referenced in the person and business tables.
To further complicate things, in the Person and Business tables, Phone_Nums_Id isn't technically a FK as in the relationship is not enforced in the test database I'm using.
I would like to construct Person and Business to have a collection of Phone_Nums on them however the mapping is eluding me. Using composite elements I am able to have hibernate properly build the query however it passes in the wrong search Criteria. For example for Person it passes in the Person_Id value instead of the Phone_Nums_Id on the record thus returning no or incorrect results.
Is what I'm attempting to do even possible or should I start the ball rolling on getting this more normalized, a task I'm not sure can be done?