File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes mapping three tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "mapping three tables" Watch "mapping three tables" New topic

mapping three tables

sammeta Phanikumar
Ranch Hand

Joined: Oct 25, 2007
Posts: 81
Hi Friends,

I am new to ORM/hibernate please help in this.

I have the follwoing table structure.

Table_A: (a_Id [PK], a_Desc)
Table_B: (b_Id [PK],b_Desc)

These two tables hbm files are working fine.

Now I want to have a mapping table description as below.

Table_Mapping( b_Id [PK], a_Id, mapping_Desc)

Here I want B table primery key b_Id as forieng key to Table_Mapping. And when an entry in Table_Mapping is removed it should not effect any way in either of A and B tables.

Please help in this.

I have found some example on google, but they say keep an instance of Table_Mapping entry in Table_B.hbm, But why like that.

It is all mapping table have reference of other two tables, these two tbales do not know any thing about Mapping. I think they need not to know.

Please help me to understand this, if am wrong.

I appreciate a quick response.

Thanks in advance.

Ravishanker kumar
Ranch Hand

Joined: Jul 20, 2006
Posts: 53
It will be better if you can provide relation between objects A,B and Mapping.
for A and B,

what about third one?
sammeta Phanikumar
Ranch Hand

Joined: Oct 25, 2007
Posts: 81
Thanks Ravi for your reply,

Here are the details.

These two classes are working fine because there are opereated independent.

Now I want a third class Mapping. Relation between A and B are: A -> B(many to one) and B->A(One to One)

class Mapping
int a_Id;
int b_Id;
String mapping_Desc;

I want add/deletion in Mapping table should not reflect in either of Table A and B.
But for any entry in Mapping then Mapping->a_Id ,a_Id should be in Table_A and Mapping->b_Id ,b_Id should be in B table.

Please reply.

sammeta Phanikumar
Ranch Hand

Joined: Oct 25, 2007
Posts: 81

Please reply any one, if the problem is not clear, let me know i will explain.

I agree. Here's the link:
subject: mapping three tables