Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Map mapping problem

 
Tom Steele
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all! Hibernate newbie here, I've been using these forums over the last couple days to iron out some issues I have been having, so thanks! and thanks in advance for any help on this issue. I'm sure I am just missing something dumb

I have two tables:
hotel:
hotel_id PK
locale PK
...
other fields
...

hotel_images:
hotel_id PK
name PK
location

I want to map the images to the hotel object as a Map (name, location). It was working fine before adding in the locale as part of the composite id of hotel, but after that it started complaining. I have tried several different ways but nothing seems to be working.



this one generates the following error

Foreign key (FKD652B63B418ADC3:hotel_images [hotel_id])) must have same number of columns as the referenced primary key (hotel [hotel_id,locale])

so then I tried it with property-ref:



which generates the error

Hibernate operation: could not initialize a collection:
bad SQL grammar [select images0_.id as id0_, images0_.location as location0_, images0_.name as name0_ from hotel_images images0_ where images0_.id=?];
nested exception is java.sql.SQLException: Unknown column 'images0_.id' in 'field list'

obviously there is no id field in hotel images so that's why that sql is failing.

I'm not sure what else to try, any ideas would be greatly appreciated!

Thanks,
Tom
[ July 24, 2006: Message edited by: Tom Steele ]
 
Ghulam Rashid
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<map name="images" table="hotel_images">
<key property-ref="hotelId"/>
<map-key column="name" type="string"/>
<element column="location" type="string"/>
</map>

I am suspecting your entry here - <map-key column="name" type="string"/>
map-key column generally refers FK (if I am not wrong), but in this case, it is PK.

This could be the possible reason.

Thanks
 
Tom Steele
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Ghulam. Hmm, i figured it was just saying which column was the key of the map. I tried changing it to <index> but that just gave me the exact same errors.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic