For some reason, <inverse-one-to-one> generates a Set instead of a simple pointer.
I'm a bit surprised it's generating a Set instead of emitting an error message explaining why it must be a <many-to-one>.
Details (nonkey columns elided except for one example in each table):
The table being referenced:
Code:
CREATE TABLE "HF_DI_BVKRIT" (
  "BKID" NUMBER(27,0) NOT NULL ENABLE, 
  "VERSION" NUMBER(18,0) DEFAULT 0 NOT NULL ENABLE, 
  "BKNAME" VARCHAR2(40) NOT NULL ENABLE
) ;
ALTER TABLE "HF_DI_BVKRIT" ADD CONSTRAINT "HF_DI_BVKRIT_PK"
  PRIMARY KEY ("BKID") ENABLE;
The table with the foreign key:
Code:
CREATE TABLE "HF_DI_BVKOPF" (
  "BVID" NUMBER(10,0) NOT NULL ENABLE, 
  "VERSION" NUMBER(18,0) DEFAULT 0 NOT NULL ENABLE, 
  "BVBKID" NUMBER(27,0) NOT NULL ENABLE, 
  "BVGPRS" NUMBER(8,2)
) ;
ALTER TABLE "HF_DI_BVKOPF" ADD CONSTRAINT "HF_DI_BVKOPF_PK"
  PRIMARY KEY ("BVID") ENABLE;
ALTER TABLE "HF_DI_BVKOPF" ADD CONSTRAINT "HF_DI_BVKOPF_UK"
  UNIQUE ("BVBKID") ENABLE;
ALTER TABLE "HF_DI_BVKOPF" ADD CONSTRAINT "HF_DI_BVKOPF_FK_BVKRIT"
  FOREIGN KEY ("BVBKID") REFERENCES "HF_DI_BVKRIT" ("BKID") ENABLE;
Relevant section from my hibernate.reveng.xml:
Code:
  <table name="HF_DI_BVKOPF">
    <column name="VERSION" type="long"></column>
    <foreign-key constraint-name="HF_DI_BVKOPF_FK_BVKRIT">
      <one-to-one />
      <inverse-one-to-one />
    </foreign-key>
  </table>
This generates the following Java classes:
Code:
public class HfDiBvkrit implements java.io.Serializable {
  private BigInteger bkid;
  private long version;
  private String bkname;
  private Set <HfDiBvkopf> hfDiBvkopfs = new HashSet <HfDiBvkopf> (0);
  ...
}
public class HfDiBvkopf implements java.io.Serializable {
  private BigInteger bvid;
  private long version;
  private HfDiBvkrit hfDiBvkrit;
  private BigDecimal bvgprs;
  ...
}
The problem here is 
Set <HfDiBvkopf> hfDiBvkopfs. Having a member here is okay (it's the backlink for 
HfDiBvkrit hfDiBvkrit in 
HfDiBvkopf), but it should be of type 
HfDiBvkopf, not 
Set <HfDiBvkopf>.
Note that the unique key on BVBKID makes it impossible for multiple BVKOPF records to reference the same BVKRIT record. I had expected that unique key would make Reveng recognize this as a (weak) one-to-one association.
Oh, and yes, I'm 100% sure that <inverse-one-to-one> generates a 
Set.
With 
<inverse-one-to-one exclude="true"/>, I don't get the 
Set (but no non-
Set backlink either).
Is there already a JIRA entry that the reference docs don't explain the usage of <one-to-one> and <inverse-one-to-one>?
Such as the following information bits (please correct any factual errors im making! - this is my current understanding of what reveng does, if I'm wrong, I have no chance of this ever getting to work):
- Explaining that the foreign key needs to reference a full primary or unique key on the foreign table, else it would be a one-to-many relationship (which would have to be declared on the other table anyway)
- Explaining that the foreign key needs to be unique (PK or just a unique index), else we have a many-to-one relationship and people should use <many-to-one> and <set> instead of <one-to-one> and <inverse-one-to-one>.