I'm reverse engineering a data table with composite natural keys, and a many-to-one relationship to a lookup table that associates a string with a field of the id.
Trouble is, the generated class does not fetch the associated strings.
Details:
hibernate.reveng.xml snippet:
Code:
<table name="HF_DI_ARTDSP">
<primary-key>
<key-column name="AOFIRM" />
<key-column name="AOSTOR" />
<key-column name="AOIDENTNR" />
</primary-key>
<foreign-key foreign-table="HF_DI_LI_FIRMA">
<column-ref local-column="AOFIRM" foreign-column="FIFIRM" />
<many-to-one update="true" insert="true" />
<set/>
</foreign-key>
</table>
<table name="HF_DI_LI_FIRMA">
<primary-key>
<key-column name="FIFIRM" />
</primary-key>
</table>
HF_DI_LI_FIRMA also as an FITEXT field that contains the display string associated with a (numeric) FIRM id.
The generated class looks like this:
Code:
@Entity
@Table (name = "HF_DI_ARTDSP")
public class HfDiArtdsp implements java.io.Serializable {
private HfDiArtdspId id;
private HfDiLiStandort hfDiLiStandort;
...
@ManyToOne (fetch = FetchType.LAZY)
@JoinColumns ( {
@JoinColumn (name = "AOFIRM", referencedColumnName = "STFIRM", nullable = false, insertable = false, updatable = false),
@JoinColumn (name = "AOSTOR", referencedColumnName = "STSTOR", nullable = false, insertable = false, updatable = false)
})
public HfDiLiStandort getHfDiLiStandort () {
return this.hfDiLiStandort;
}
public void setHfDiLiStandort (HfDiLiStandort hfDiLiStandort) {
this.hfDiLiStandort = hfDiLiStandort;
}
...
Now... how to I generate a new row for this?
I have this:
Code:
row = new HfDiArtdsp ();
row.setId (new HfDiArtdspId (5, 1, "123456")); -- sample values for primary key
row.save ();
row.refresh ();
System.out.println (row.getHfDiLiStandort ()); -- prints "null"
No row with AOFIRM=5, AOSTOR=1, AOIDENTNR='123456' exists when this is run.
A row with FIFIRM=5 does exist in HF_DI_LI_FIRMA.
Running
Code:
row = (HfDiArtdsp) session.load (HfDiArtdsp.class, new HfDiArtdspId (1, 1, "123456"));
System.out.println (row.getHfDiLiStandort ()); -- prints a non-null object
does work if a row with AOFIRM=1, AOSTOR=1, AOIDENTNR='123456' does exist. So somehow the hfDiLiStandort field of row is not initialized with an on-demand-loading proxy during save(), it seems.
Maybe it's a problem just with fields from a composite id?
I haven't tried whether the effect exists for non-id fields.
I'm also utterly confused about the various attributes that you can set for <many-to-one> and <set> in the hibernate.reveng.xml. There's a bewildering array of options, and it's unclear which option does what. Googling gave me pages that simply listed the options, which didn't help.
Any ideas and pointers welcome.