Hi,
Based on my functional requirements, I have modeled two classes A nd B with a one-to-many relation from class A to class B. Ideally, I would prefer to have two tables A_TBL and B_TBL with a FK constraint to hold the data for classes A and B respectively. But our DB model holds the data for both classes in a single table AB_TBL. One record in AB_TBL can hold data for one A object and 10 B objects. DB model was done based on the assumption that A entity will not have more than 10 B entities associated with it.
We dont know the exact reason for why DB was modeled like this? It could be by mistake or intentional denormalization. I myself didn't like it, but we have to live with it.
Is there a way to map directly the attributes of A and B classes to AB_TBL?
One option I have on mind is to introduce a new class AB which would be mapped to AB_TBL. The data from A object and associated B objects would be copied into an AB object and then AB obejct is persisted to DB. The data copying logic would ideally be encapsulated using a DAO class.
But I prefer to do a direct mapping of attributes of A and B classes to AB_TBL if that is possible.
Please let me know.
Thanks in advance for your help,
Balaji.
|