This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.
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.
Joined: Dec 26, 2008
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.