| 发表于:2007-09-30 09:45:44 楼主 |
<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- mapping file autogenerated by myeclipse - hibernate tools --> <hibernate-mapping> <class name="model.articletype" table="articletype" catalog="javasubject" > <id name="arttid" type="long"> <column name="artt_id" /> <generator class="native" /> </id> <many-to-one name="parent" class="model.articletype" fetch="select" outer-join="true"> <column name="artt_up" /> <!-- 指向当前类型的父类型 --> </many-to-one> <property name="arttname" type="string"> <column name="artt_name" length="20" /> </property> <property name="artttype" type="string"> <column name="artt_type" length="20" /> </property> <set name="articles" inverse="true" cascade="all" > <key> <column name="artt_id" /> </key> <one-to-many class="model.article" /> <!-- 与article一对多关联 --> </set> <set name="children" inverse="true" cascade="all" lazy="false"> <key> <column name="artt_up" /> </key> <!-- 指向当前类型的子类型 --> <one-to-many class="model.articletype" /> </set> </class> </hibernate-mapping> 以上是我的articletype(文章分类)的hbm.xml文件,articletype与article是一对多关联 我以前刚刚写好dao层的时候,做过测试的, 删除articletype,是可以级联删除article(文章), 但是,现在,整合了struts1.2以及spring2.0以后,既然删掉articletype时,如果有所下属的 article.就会出现以下的提示错误: could not EXECute jdbc batch update; sql [delete from javasubject.article where art_id=?]; cannot delete or update a parent row: a foreign key constraint fails (`javasubject/favorite`, constraint `fk_favorite2` foreign key (`art_id`) references `article` (`art_id`)); nested exception is java.sql.batchupdateexception: cannot delete or update a parent row: a foreign key constraint fails (`javasubject/favorite`, constraint `fk_favorite2` foreign key (`art_id`) references `article` (`art_id`)) 我的article表与review表,也是一对多关联, 删除article时,却可以级联删除review,以下是hbm.xml: <?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- mapping file autogenerated by myeclipse - hibernate tools --> <hibernate-mapping> <class name="model.article" table="article" catalog="javasubject"> <id name="artid" type="long"> <column name="art_id" /> <generator class="native" /> </id> <many-to-one name="articletype" class="model.articletype" fetch="select" outer-join="true" > <column name="artt_id" /> </many-to-one> <property name="arttitle" type="string"> <column name="art_title" length="50" /> </property> <property name="artauthor" type="string"> <column name="art_author" length="20" /> </property> <property name="arttext" type="string"> <column name="art_text" length="65535" /> </property> <property name="artsource" type="string"> <column name="art_source" length="50" /> </property> <property name="arttype" type="string"> <column name="art_type" length="20" /> </property> <property name="arttime" type="timestamp"> <column name="art_time" length="0" not-null="true" /> </property> <set name="reviews" inverse="true" cascade="all"> <key> <column name="art_id" /> </key> <one-to-many class="model.review" /> </set> <set name="keywords" inverse="true" cascade="all"> <key> <column name="art_id" /> </key> <one-to-many class="model.keyword" /> </set> <set name="users" inverse="true" table="favorite"> <key> <column name="art_id" not-null="true" /> </key> <many-to-many class="model.user" column="user_id" outer-join="auto"/> </set> </class> </hibernate-mapping> 请高手帮助看看,我真的不知道出在哪里,,很奇怪。。 |
|
|
|
|