File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Hibernate Repeated column mapping problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Repeated column mapping problem" Watch "Hibernate Repeated column mapping problem" New topic

Hibernate Repeated column mapping problem

Vince Lee

Joined: Oct 15, 2006
Posts: 7
hi, I'm new to Hibernate, and I'm running into a bit of problem when specifying my mappings.

Currently I have a UserBean class:

and my UserBean mapping file looks like:

my RankingBean class looks like:

and RankingBean's mapping file is:

so, the error i'm getting says :

INFO - Reading mappings from resource: com/uwa/beans/UserBean.hbm.xml
INFO - Mapping class: com.uwa.beans.UserBean -> tblUser
INFO - Mapping collection: -> tblParticipate
INFO - Configured SessionFactory: null
INFO - Mapping collection: -> tblLoan
INFO - Mapping collection: com.uwa.beans.UserBean.rankings -> tblRanking
org.hibernate.MappingException: Repeated column in mapping for entity: com.uwa.beans.RankingBean column: userID (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(

I'm wondering if someone could tell me what the error is, because I seem to already have duplicated column="userID" in the events and loans collection mapping and it didn't complain there? thanks

[ October 30, 2006: Message edited by: Vince Lee ]

[Edited to include code tags - Paul Sturrock]
[ October 30, 2006: Message edited by: Paul Sturrock ]
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
Parsing of the config files stops after the first error is encountered. If you fix the first problem then hibernate will complain about the next error (if there are more).

- for the events/loans/rankins collections hibernate will create a column named "userId" in the events/loans/rankins tables, not in the user table. so there is no problem with duplicated columns in the user table
- it looks like the problem occur because your FK to user is also part of the PK in the rankins table
- (if not required then) do not use a composite key, use a surrogate key. easier to manage, map, code, query and so on.

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

"userID (should be mapped with insert="false" update="false")"

This is related to mapping relationships. Just add the above(insert="false" update="false") to your userID mapping, and that should get it to work.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Anand Wadhwani
Ranch Hand

Joined: Mar 21, 2005
Posts: 151
I'm also having this problem.
And when I try to add these attributes to the JoinColumn annotation in my JPA POJO, I get error that these are not valid attributes of JoinColumn annotation.
I'm going to try the insertable, and updatable attributes and see if that helps.
Mean while if anyone has any pointers, please share.

SCWCD 1.4<br />---------------------<br />Ability is what you're capable of. <br />Motivation determines what you do. <br />Attitude determines how well you do it.<br />---------------------
Anand Wadhwani
Ranch Hand

Joined: Mar 21, 2005
Posts: 151
Hey there!
After adding insertable, updatable attributes to JoinColumn annotation, it resolved the problem.
Thank you, you guys are awesome!
I agree. Here's the link:
subject: Hibernate Repeated column mapping problem
It's not a secret anymore!