首先,要在建表SQL中加入对级联删除的支持
CREATE TABLE `voteitem` (
`id` varchar(50) NOT NULL default '',
`title` varchar(50) default NULL,
`votenum` varchar(50) default NULL,
`vote_id` varchar(50) NOT NULL,
PRIMARY KEY (`id`),
KEY `vote_id` (`vote_id`),
CONSTRAINT `voteitem_ibfk_1` FOREIGN KEY (`vote_id`) REFERENCES `vote` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=gb2312 ROW_FORMAT=COMPRESSED;
其次,在hibernate mapping文件中设置cascade