Ok, I use 3 entities:
GenDist
- PK gen_dist_id
Gen
- PK gen_id
GenFreq
- PK gen_dist_id (foreign key of GenDist)
- PK gen_id (foreign key of Gen)
GenFreq has a composite pk, implemented in the class GenFreqPK. This is the code of the entities and the class, after removing some properties to improve readibility:
Code:
@Entity
public class GenDist implements Serializable {
private long id;
@Id(generate = GeneratorType.SEQUENCE, generator = "gen_dist_seq")
@Column(name = "gen_dist_id")
public long getId() {
return id;
}
public long setId() {
return id;
}
// more properties here
}
Code:
@Entity
public class Gen implements Serializable {
private long id;
@Id(generate=GeneratorType.SEQUENCE, generator="GEN_SEQ")
@Column(name="gen_id")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
// other properties here
}
Code:
@Entity
public class GenFreq implements Serializable {
private GenFreqPK genFreqPK;
@EmbeddedId
public GenGreqPK getId() {
return genFreqPK;
}
// other properties here
}
Code:
@Embeddable
public class GenFreqPK implements Serializable{
@ManyToOne(targetEntity="GenDist")
@JoinColumn(name="gen_dist_id")
public GenDist getGenDist() {
return genDis;
}
public void setGenDist(GenDist genDist) {
this.genDist = genDist;
}
@ManyToOne(targetEntity="Gen")
@JoinColumn(name = "gen_id")
public Gen getGen() {
return gen;
}
public void setGen(Gen gen) {
this.gen = gen;
}
}
If there is only one of the @ManyToOne in the GenFreqPK class everything works, but when I use both, the exception is thrown. It does not depend in the @ManyToOne I choose. It always work as expected with one, but no two...
Thanks,
Bruno