I’m trying to use hibernate reverse engineering on some tables in myeclipse.
It works, but my first problem was that many of the tables are views, or have no primary keys or foreign keys defined at the DB level. And unfortunately they’re not going to be. But I know what columns contain the unique ids.
I figured out from the forums here that I could manually edit hibernate.reveng.xml with lines like:
<table name=”MY_TABLE”…
<primary-key>
<key-column name=”MY_TABLE_ID” />
</primary-key>
</table>
To force the reverse engineering ot use MY_TABLE_ID as an id rather than creating a composite-id.
That worked. But now I’m trying to manually define a foreign key the same way.
I’ve tried several things, but the reverse engineering doesn’t seem to honor this one. It seems to me this should work:
<table name=”MY_TABLE”…
<foreign-key foreign-table=”MY_OTHER_TABLE”>
<column-ref local-column=”OTHER_ID” foreign-column=”OTHER_ID” />
<many-to-one property=”otherTable”/>
</foreign-key>
</table>
There are no errors during the reverse engineering, it still generates all the POJOs but it still doesn’t generate the references between the objects like it does when there is a true foreign key defined in the database. Am I doing this wrong, or does this not work for foreign keys like it did for primary keys?