Foreign-key constraint to have the "on delete cascade" option in the generate DDL

7 views
Skip to first unread message

JadziaPM

unread,
Sep 21, 2008, 1:14:59 PM9/21/08
to nhusers
Hello,
I am currently having an issue when using NHibernate 2.0.0 and
MySQL5Dialect
Basically I wish my foreign-key constaints to have ON DELETE CASCADE
ON UPDATE CASCADE
However when I generate my Database schema these constraints are
missing.

I have 3 tables [1] Fixture and the other [2] Team [3] FIxtureTeam

----------------------FIxture----------------------------------
<id name="Fixtureid" column="fixtureid" type="long">
<generator class="native" />
</id>
<bag name="TeamsThatPlayedInThisFixture" inverse="true"
table="fixtureteam" lazy="true" cascade="all" >
<key column="fixtureid" />
<one-to-many class="FixtureTeam" />
</bag>
--------------------------------------------------------

----------------------Team----------------------------------
<id name="Teamid" column="teamid" type="long">
<generator class="native" />
</id>
<property type="string" not-null="true" length="50"
name="Teamname" column="teamname" unique="true"/>
<bag name="FixtureHistory" inverse="true" table="fixtureteam"
lazy="true" cascade="all">
<key column="teamid"/>
<one-to-many class="FixtureTeam" />
</bag>
--------------------------------------------------------

So Fixture has a one to many relationship with FixtureTeam
That is, there are two teams per fixture

----------------------FIxtureTeam----------------------------------
<!-- A composite primary key, made up from the primary keys
(fixtureid, teamid) from fixture and team tables -->
<composite-id name="FixtureTeamid" class="FixtureTeamCompoundKey">
<key-property type="long" name="Fixtureid" column="fixtureid"/>
<key-property type="long" name="Teamid" column="teamid" />
</composite-id>
--------------------------------------------------------

I seem to be having the same issue as the Java version MySQL5Dialect
Issue here.
-----------------------------------------------------------------
http://forum.hibernate.org/viewtopic.php?t=986157
--------------------------------------------------------------

Any suggestions would be great.

Fabio Maulo

unread,
Sep 21, 2008, 6:01:40 PM9/21/08
to nhu...@googlegroups.com
In general NH don't generate any kind of constraint because the NH-cascade do the right thing (much more complex than a "simple" trigger).
BTW to have better performance on in case of cascade="delete" we had a new feature in NH2.0:
The tag on-delete="cascade" .
That tag create an ON DELETE CASCADE.
It if very important to remember that tag <cascade> and the tag <on-delete> are two very different things (see reference).
Bye.
Fabio Maulo.

2008/9/21 JadziaPM <jad...@o2.ie>



--
Fabio Maulo
Reply all
Reply to author
Forward
0 new messages