I have a table that has no primary key (this is a legacy table so it is not possible to change it now.) The middlegen plugin is correctly placing all of the columns as part of the composite pk. However, one of the columns happens to be a many-to-one association. But the plugin is generating the hbm xml for this column as if it were a regular association, e.g. it is generating a many-to-one instead of a key-many-to-one. Is this a bug?
Here is a listing of my generated xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="testQwb.hibernate.persistent.QwEnvrmt"
table="QW_ENVRMT"
>
<composite-id>
<key-property
name="hldJobSw"
column="HLD_JOB_SW"
type="java.lang.String"
length="1"
/>
<key-property
name="maxThrdCnt"
column="MAX_THRD_CNT"
type="int"
length="3"
/>
<key-property
name="lastNdmTs"
column="LAST_NDM_TS"
type="java.sql.Timestamp"
length="7"
/>
</composite-id>
<!-- associations -->
<!-- uni-directional one-to-one association to QwEnvrmtCd -->
<many-to-one
name="qwEnvrmtCd"
class="testQwb.hibernate.persistent.QwEnvrmtCd"
>
<column name="ENVRMT_CD" />
</many-to-one>
</class>
</hibernate-mapping>
notice that the many-to-one association is not a key-many-to-one that is part of the composite key.
Beleive it or not this makes a difference for what I am trying to accomplish. Specifically I am creating a renderer for hbm2java to output DAO classes. I need some way to determine if a class has no pk, in which case certain methods would not be output. The only way I can think of to accomplish this is to check all the fields and running FieldProperty.isIdentifier() on them. If all the fields are an identifier then I assume the class has no PK. However since middlegen does not render the many-to-one as part of the key the isIdentifier() for the field returns false, incorrectly indicating that the table HAS a pk. If there is no way to render the association as a key-many-to-one, does anyone perhaps some other method to determine if a table has no pk?
Thanks,
Daniel