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 :)