Search code examples
hibernatejakarta-eereverse-engineeringjavadb

Hibernate Mapping Files and POJOs from DB (Reverse Engineering) doesn't generate Foreign Keys


I did this tutorial, and configured the Hibernate API and the mapping: https://netbeans.org/kb/docs/web/hibernate-webapp.html

(i'm using the JavaDB API with the 'sample' DB not MySQL)

But i have a problem: the generated hbm.xml files dont contain any foreign key mapping. (there are no one-to-many or many-to-one properties)

here is a sample class and mapping file. the RoleID should be a foreign key to the ROLE table ID field.

http://pastebin.com/tGnPTrXx

http://pastebin.com/bq4Q4RTi

im trying to edit the hibernate.reveng.xml file to force creating FK's - something like this:

<table name="USERS">
    <foreign-key constraint-name="ROLE_USER_FK" foreign-table="ROLE">
        <column-ref local-column="roleid" foreign-column="id" /> 
        <many-to-one property="roleid" />
    </foreign-key>
</table>

but it doesnt work.


Solution

  • solved: hibernate.cfg.xml needed the hibernate.default_catalog and hibernate.default_schema property