This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Repeated column mapping problem" Watch "Hibernate Repeated column mapping problem" New topic
Author

Hibernate Repeated column mapping problem

Vince Lee
Greenhorn

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: com.uwa.beans.UserBean.events -> tblParticipate
INFO - Configured SessionFactory: null
INFO - Mapping collection: com.uwa.beans.UserBean.loans -> 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(PersistentClass.java:605)
...


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.


pascal
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

"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.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
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: http://aspose.com/file-tools
 
subject: Hibernate Repeated column mapping problem