-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: many-to-one not created as foreign key
PostPosted: Mon Sep 03, 2007 4:33 pm 
Beginner
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.