This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Creating a composite-id with 2 columns, only one of them is a foreign key to another table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Creating a composite-id with 2 columns, only one of them is a foreign key to another table" Watch "Creating a composite-id with 2 columns, only one of them is a foreign key to another table" New topic
Author

Creating a composite-id with 2 columns, only one of them is a foreign key to another table

Wassim Melhem
Greenhorn

Joined: Nov 19, 2012
Posts: 3
Hi all,

So I am kinda new to hibernate and it's been days I'm trying to solve this problem I am getting with the mapping, hope someone can help

I tried to search a lot, found lots of similar questions but none really applying to my case. I have a table TABLE1 which has an index "id" and another table which has as index (TABLE1_ID and NUMBER). Only TABLE1_ID is a foreign key while number doesn't reference anything specific

TABLE 1 has the following hibernate mapping




I am not sure what should be the mapping for the other table. I did it the following way



Please note that I created the class TABLE1TABLE2Id after I read somewhere that there should be some intermediate mapping.

I am sure there's something wrong or missing from TABLE2 mapping (I am not so advanced with hibernate) but when trying to install the app, I am getting the following error
Foreign key (TABLE1 [id]) must have same number of columns as the referenced primary key (TABLE2 [TABLE1_ID, NUMBER])

I appreciate anybody's help thanks
 
GeeCON Prague 2014
 
subject: Creating a composite-id with 2 columns, only one of them is a foreign key to another table