• 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

Hibernate2, composite-id, mappingException

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey folks,

I really searched the forums for my problem but I couldn't find a working solution for my problem, which is :

- I've got two mappings.
- Both have a composite-id.
- One mapped class has a Set of the second mapped class
- on server startup I get an Hibernate MappingException:

Foreign key (BAR [FOO_ID,LANGUAGE])) must have same number of columns as the referenced primary key (FOO [FOO_ID])



The Mappings are as stated below:





The class com.Foo has the fields
- fooId, language (String)
- bars (Set)

The class com.Bar has the fields
- barId, language

The table FOO has the columns
- FOO_ID, LANGUAGE

The table BAR has the columns
- BAR_ID, LANGUAGE, FOO_ID



O.k. - Sorry for this mega text but I REALLY have no clue
how to solve my problem. Hopefully somebody in here has.

For today I will shutdown my computer and hope that some
wise pixie will drop me a sulotion that night

Thanx a lot in advance!
Thomas


 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey

not sure whats wrong... some ideas:
- change your BAR table to
BAR_ID, LANGUAGE_BAR, FOO_ID, LANGUAGE_FOO
perhaps hibernate is complaining because you are sharing the LANGUAGE column as part of the PK and as part of the FK ?

- Do not use compund primary keys at all unless you are required to do so (legacy DB). Instead use a surrogate key. Easier to handle, also in relationships.


Pascal
 
Thomas Rochon
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your reply, Pascal!

Unfortunately I'm not able to change any table names because it's a legacy DB.
I found a mapping example on the Hiberante homepage which I will translate for my case. But I guess you're right, regarding your suggestion about the LANGUAGE column. If that's the problem, I've got a tiny problem

Well ... I will check the alternatives ... and maybe visit this forum again.

Finally, thanks again!
Thomas

* follow-up *

O.k. - I've checked the manuals in more detail and now the error message seems to make more sense to me. If I got it right, then the FK MUST have the same (number of) keys as the PK of the table I want to reference to (that's exactly what the error message is saying).

At this point I'm in deep trouble because the legacy DB model was designed by some kind of evil wizard. I have a bunch of tables, all with two or more PKs. Most of them do not have a matching FK combination for the given PK combinations of the tables they should reference to. I'm not allowed to modify the existing tables but forced to map them into Hibernate. I'm trapped within a nightmare ...


Well ... I will check the alternatives ... and maybe visit this forum again.



Thanks!
Thomas
[ November 30, 2006: Message edited by: Thomas Rochon ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic