Beginner |
|
Joined: Mon Sep 03, 2007 4:25 pm Posts: 24
|
I have a case where the sql schema fails to recognize and declare a foreignkey. I am using mysql and hibernate 3.2
parent:
<class name="com.jcalc.core.page.TemplateAbs" >
<id name="templateId" type="int" column="TEMPLATEID" >
<generator class="hilo">
<param name="table">hi_value</param>
<param name="column">next_value</param>
<param name="max_lo">100</param>
</generator>
</id>
<list name="forms" cascade="all-delete-orphan" >
<key column="TEMPLATEID" not-null="true"/>
<list-index column="formIdx"/>
<one-to-many class="com.jcalc.core.page.Form"/>
</list>
</class>
child:
<class name="com.jcalc.core.page.Form" table="Form">
<id name="formId" type="int" column="FORMID" >
<generator class="native" />
</id>
<many-to-one name="template"
class="com.jcalc.core.page.TemplateAbs"
column="TEMPLATEID"
not-null="true"
insert="false"
update="false"/>
</class>
but the database schema for form came out
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| FORMID | int(11) | | PRI | NULL | auto_increment |
| TEMPLATEID | int(11) | | | 0 | |
| formIdx | int(11) | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
as you can see, the TEMPLATEID field is NOT marked as a foreign key.
I don't have this problem any other time, I use <many-to-one > mapping. Hibernate always would create the parent field with MUL designation in the Key attribute.
anyone has any idea? is it useful to post the java classes too?
Thanks
|
|