• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with joining of two tables with Hibernate

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Hibernate mapping against a database table which is working. However I have another table which contains extra information. I've tried a join in the mapping file but somehow it fails.

Lets call them Table1 og Table2.
Table1 has an attribute TAB1_Var_ID(not a primary key)
Table2 has a primary key TAB2_Var_ID which is connected to the TAB1_Var_ID
There is a many-to-one relationship.
Table1 can contain many TAB2_Var_ID

I am fairly new with Hibernate and don't have a clue what the cause of my problem is. Heres is my join mapping



The Class for Table1 inherits from a parent class which contains some of the values retrieved from persistence. tab1VarID is an variable in the parent class.

The error message I get from UnitTest is a MappingException


Foreign key (Table2 [TAB2_Var_ID]) must have same number of columns as the referenced primary key (Table1 [primaryKey1, primaryKey2, primaryKey3])



But I thought that property-ref "Specifies that the foreign key refers to columns that are not the primary key of the orginal table.". And the original table is Table1. Or is it?

Edit: I receive the same error with and withouth the property-ref in <key>

It seems that the tables are reversed. It is saying something about the foreign key which is in Table2. But the foreign key is in Table1.

TAB1_Var_ID in Table1 is not defined as a foreign-key in the SQL level. That is a database design I cannot meddle with
[ August 06, 2007: Message edited by: Sverre Moe ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic