• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate - mapping FK from one column to two different tables  RSS feed

Tinker Tailor
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,

I'm pretty new to hibernate and i'm working on a module which consists of 3 tables namely Doc_fees_master , Test_fees_master and there is an itemised_bill table , and the relation is as follows

itemised_bill - ID , Fees_id , fees_type

doc_fees_master - ID , fees , Doctorname , specialization

test_fees_master - ID , testname , fees

Now the fees_id field in itemised_bill is the ID field of doc_fees_master , so it could be like Fees_id=1 can exist in both doc_fees_master and test_fees_master , or in any one of them .

Ex : if fees_id=1 and fees_type=1 , then it means it's a foreign key to doc_fees table
if fees_id=1 and fees_type=2 , then it means it's a foreign key to test_fees table

i'm using hibernate and i tried to map many-to-one relation on fees_id(itemised_bill) to both doc and test tables , which doesn't work , because same column cannot be referenced to 2 different tables , please let me know the right mapping to be done in hibernate using XML file and not annotations.

my objective is that , i would like to join itemised_bill and doc_fees and test_fees in so that with one foreign key fees_id , so that ill get the bill itinerary or a particular person .
Thank you
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!