Hello,
i have a problem with code generate by Reverse engineering.
I have the following table:
ASSISTIBILI, which has
Primary Key : PKASSISTIBILI
Foreign Key: ASSISTIBILI_FK which refers to ASSISTIBILI.PKASSISTIBILI
This is a composite, where each record can have a reference to another record in the same table. the association is *--->1
The generated code contains the following methods:
public Assistibili getAssistibili() {
return this.assistibili;
}
public void setAssistibili(Assistibili assistibili) {
this.assistibili = assistibili;
}
public Set getAssistibilis() {
return this.assistibilis;
}
public void setAssistibilis(Set assistibilis) {
this.assistibilis = assistibilis;
}
And the mapping file contains:
<set name="assistibilis" inverse="true">
<key>
<column name="ASSISTIBILI_FK" precision="9" scale="0" />
</key>
<one-to-many class="com.reveng.Assistibili" />
</set>
Somebody can explain to me why i have the method:
public void setAssistibilis(Set assistibilis) {
this.assistibilis = assistibilis;
}
??
The referred record can be only one!!!!!!
Why can i set a collection of objects?
Anyway, i try to use the code in this way:
Assistibili ass1 = (Assistibili)em.find(Assistibili.class, new Integer(1259));
Assistibili ass2 = (Assistibili)em.find(Assistibili.class, new Integer(1260));
ass1.setAssistibili(ass2);
commit();
After this when i go to see on the database, my foreign Key field is still empty!!!!!
Can i set the referred object in this way??
If not, how should i do?????
Greetings,
Fabio
|