I tried now a couple of different scenarios where I defined two tables (with a 1:n) relationship) in a MySQL database and used Hibernate Tools to generate corresponding, annotated java classes from them.
I found NO way to let Hibernate Tools generate the desired
@OneToMany(....)
or
@ManyToOne(....)
annotations. Assume for example the simplified table DDL below. Why is there no @OneToMany generated in class for TAB1? In other words: What do I have to change in the DDL to have Hibernate Tools generate such a @OneToMany (and @ManyToOne) ?
CREATE TABLE TAB1 ( ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, OTHERFIELD VARCHAR(20) NULL; PRIMARY KEY(ID), INDEX TAB1_FKIndex1(ID) );
CREATE TABLE TAB2 ( ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, DUMMYFIELD DATE NULL, REFTOTAB1 INTEGER UNSIGNED NULL, PRIMARY KEY(ID), INDEX TAB2_FKIndex1(ID), INDEX TAB2_FKIndex2(REFTOTAB1) );
|