This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes 1-to-M mapping confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "1-to-M mapping confusion" Watch "1-to-M mapping confusion" New topic

1-to-M mapping confusion

Arnie Morein

Joined: Dec 20, 2006
Posts: 16
I have three tables I'm trying to map but am getting odd messages from Hibernate (3.x). Table saved_searches has a key field of search_id and tables search_fields and sort_fields has the same field (this is the foreign key back to the parent) They then each have search_field_id and sort_field_id fields which are identity in the each of the child tables to keep the records unique. The hbm.xml files are below. I want to map the search_fields and sort_fields tables as lists of a given search. My two problems is how to tell Hibernate that when it adds records to the child tables that the second field needs to be "identity" and that the two tables are joined on the parent's key field. I keep getting:

org.hibernate.MappingException: Repeated column in mapping for entity: us.tx.state.oag.FinancialCrimesInquiry.db.HbmUserSavedSearchSortFields column: search_id (should be mapped with insert="false" update="false")

Arnie Morein

Joined: Dec 20, 2006
Posts: 16
More testing is yielding odder results.

linked to:

Keeps complaining about duplicate fields. However, taking the <composite-id> or <id> entries out of the children is a violation of the XML Schema. This is insane! How can I link via many-to-one properly listing the fields to index on, if listing them in the class in question is a duplication, especially when one of them is identity?

I agree. Here's the link:
subject: 1-to-M mapping confusion
Similar Threads
Please suggest on this Mapping
Hibernate - Force foreign key lookup on insert
hibernate mapping
Hibernate Issue
Hibernte will delete rows from a table, but it won't insert rows