The answer is pretty simple, but it took me 2 days to find:
Code:
public class LineItem implements Serializable, XmlSerializable {
private String id; // our primary key
private String otherid; // our foreign key
private Set<Component> firstSet; // onetomany linked with primary key
private Set<Component> secondSet; // onetomany linked with foreign key
@Id @Column(name="FIRSTSET_ID", insertable = false, updatable = false, nullable = false)
public String getId() { return this.id; }
public void setId(String i) { this.id = i; }
@OneToMany(fetch=FetchType.EAGER)
@JoinColumn(name="ID", referencedColumnName="FIRSTSET_ID")
public Set<ComponentData> getFirstSet() {
return lineItemData;
}
public void setFirstSet(Set<Component> c) {
this.lineItemData = lineItemData;
}
@Column(name="OTHERNONPKID")
public String getOtherid() { return otherid; }
public void setOtherid(String o) { this.otherid = o; }
@OneToMany(fetch=FetchType.EAGER)
@JoinColumn(name="ID", referencedColumnName="OTHERNONPKID")
public Set<Component> getSecondSet() {
return secondSet;
}
public void setSecondSet(Set<ComponentData> s) {
this.secondSet = secondSet;
}
The key is @JoinColumn(name="ID",
referencedColumnName="FIRSTSET_ID")
In the FirstSet case, it is optional, but not in for the SecondSet