• 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

Hibernate - id column of an entity as list-index column in another entity?

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm writing a Hibernate mapping file for my class Order.java. I'm trying to map a List collection that stores OrderItems and I would like to use id column of the OrderItem entity as the list-index column in the Order entity.

Order.hbm.xml:


OrderItem.hbm.xml:


I'm getting the following error:


I had already searched the board and I've found that I need to set the column that is mapped repeatedly as read-only, but I was unable to find how this is done in the reference documentation for Hibernate.

Thanks for any help.
Vladimir
 
Ranch Hand
Posts: 84
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Vladimir, you have an error on your mapping files. Hibernate complains on a repeated column on the table OrderItem. The problem it's not originated on this mapping but rather in the other one. You're using the same column name for the index in the list and on the id of the OrderItem identity. These columns must be different, they are not the same. The list-index it's used to save the index of the java.util.List index not the id of the OrderItem.

To solve this you only have to rename the list-index column to orderitem_id_idx or something like it.

Regards,
 
Vladimir Kroupa
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for the quick explanation! I thought that Hibernate uses list-index to figure out ordering of the elements, not to store their indeces.

Thanks again.

Vladimir
reply
    Bookmark Topic Watch Topic
  • New Topic