Hi, I was just trying to work on an O/R mapping in EJB3. Unfortunately altering the database schema is not an option (or at the very least is a last resort). Basically there are a whole bunch of tables in which one of the columns is called "Attributes_ID". Though not explicitly defined in the schema, this attributes_id maps to the column "ID" in the table "Attributetext". Because multiple tables have this relationship, no foreign key can be defined within the Attributetext table.
I was wondering whether it is still possible to have a OneToMany mapping done correctly with this. In a
java file defining a pojo corresponding to a table (let's call it "Feature") I include the following:
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name="Attributes_ID")
public Collection<Attributetext> getAttributeText() {
return attributeText;
}
public void setAttributeText(Collection<Attributetext> attributeText) {
this.attributeText =attributeText;
}
The primary key of the "Feature" table is a column called "ID" and what happens with this is for each feature the attributeText row(s) with attributes_id equal to the feature's ID value are retrieved. What I want is for the attributeText row(s) with attributes_id equal to the features attributes_id value to be retrieved and put into the Collection. It seems that any example of a OneToMany mapping I can dig up, the join is being done with the primary key column in your "One" table (in this example Feature), to that column specified by "@JoinColumn" in your "Many" table (in this example AttributeText).
Is there any option that can be set to instead do the join on a non-key column in the "One" table?
Thanks sincerely