I'm using the SchemaUpdate and HibernateTool tasks in Hibernate 3.1.2.
We use the tools to generate both POJOs and database schema from the mapping files i.e. HibernateToolTask and SchemaUpdateTask.
I am trying to map a class (FlowDetail) to 2 different tables using the entity-name attribute, however, I have a conflict when using/not using the entity-name attribute in a many-to-one entity.
I have a DisconD0132 object which has a one-to-one relationship with a FlowDetail object. These are mapped to DISCON_D0132 and DISCON_D0132_FD tables respectively. The FlowDetail object also has another mapping to a FLOW_DETAILS table.
If my mappings are as follows:
Code:
<many-to-one name="DisconD0132FlowDetail"
class="uk.co.formfill.dfcommon.domain.dfwv.FlowDetail"
column="DISCON_D0132_FLOW_DETAIL_ID"
cascade="all" unique="true" />
<class name="uk.co.formfill.dfcommon.domain.dfwv.FlowDetail"
table="DISCON_D0132_FD"
entity-name="DisconD0132FlowDetail">
this correctly generates the POJO containing a nested FlowDetail object and the correct tables, however, the foreign key generated in the DISCON_D0132 table references another table that the FlowDetail object is mapped to, FLOW_DETAILS.
If I change the many-to-one mapping to include the entity-name attribute i.e.
Code:
<many-to-one name="DisconD0132FlowDetail"
class="uk.co.formfill.dfcommon.domain.dfwv.FlowDetail"
entity-name="DisconD0132FlowDetail"
column="DISCON_D0132_FLOW_DETAIL_ID"
cascade="all" unique="true" />
this generates the correct foreign key reference, but the POJO is incorrectly generated containing a DisconD0132FlowDetail object which does not exist.
The only way I have found round this is to suppress the generation of the foreign key, but this is not really satisfactory. Could somebody tell me whether my mappings are incorrect or whether this is a bug?