-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Repeated column in mapping for entity with JPA
PostPosted: Mon Jul 11, 2011 12:32 pm 
Newbie

Joined: Wed Feb 13, 2008 7:28 pm
Posts: 5
Ok,

I understand what the problem is here, but not why.

I have the following JPA definition (notice this is a embedded composite key, survey_date, state_cd, question_id and group_id make up the unique key):

Code:
@Embeddable
public class SurveyGroupPK implements Serializable, Cloneable {

   @Column(name = "survey_date")
   private Date surveyDate;

   @Column(name = "state_cd")
   private Integer stateCode;

   @OneToOne
   @JoinColumn(name="question_id")
   private Question question;

   @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumns({
       @JoinColumn(name="group_id", insertable=false, updatable=false),
       @JoinColumn(name="state_cd", insertable=false, updatable=false)
    })
   private Group group;
 
   ...

}


This results in a org.hibernate.MappingException: Repeated column in mapping for entity: gov.usda.nass.cpcs.beans.data.SurveyGroup column: state_cd (should be mapped with insert="false" update="false")

Obviously, the issue is that the state_cd column is mapped twice, but I feel like I should be able to do this somehow. The state code is part of the foreign key to the Group table, but I also want it as part of the SurveyGroup object, especially since the Group relationship is lazy (and not guaranteed to be there). Am I just missing something obvious that would allow me to have state_cd mapped to the stateCode attribute as well as use it as part of a foreign key to another table? An alias perhaps?

Thanks very much! This newbie is still learning :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.