• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Mapping One to One relationship with composite id

 
Zaw Aung
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I want to know how to make the one to one relationship in hibernate mapping file(*.hbm.xml) and java classes

I have two tables . MainTransaction and SubTransaction

MainTransaction Table has four fields

1.Transaction ID (Primary Key)
2.BranchID
3.BranchName
4.BranchAddress

BranchID and BranchName are foreinkey to link to SubTransaction Table..

SubTransaction Table has five fields

1.BranchID
2.BranchName
3.Location
4.Activity

BranchID and BranchName are composite id to link to MainTransaction Table.

I already created the SubTransactionPK class for composite id.

Please tell me how to create the hibernate mapping files (*.hbm.xml) and java classes(entity classes) for those two tables relationship.

With Regards,
Aung




 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i think you are a begginer in Hibernate world. i would suggest to avoid using primary keys that have meanings and there is a little possibility that you have one day to change them, since hibernate will not allow you to do that, so i would suggest to add a new column to the SubTransaction table that is just a number with no meaning and then map the whole stuff using a normal many to one ;)



(peace)
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you know we have a forum for ORM questions? I'll move this for you. Don't worry. The original location will link right to the new thread.
 
Zaw Aung
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But I can't change the table primary key. I am using the legacy database.
Any other ideas???

Thanks a lot....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic