hibernate 使用注解进行由副表维护的级联删除
在网上看了下级联删除都是主表删除的时候同时删除副表的相关数据,可不可以弄成副表删除时同时删除主表数据?数据库
主表:应用--终端 关系表
CREATE TABLE `r_terminal_application` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`application_version_id` bigint(20) NOT NULL,
`terminal_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `FK1C2451BA760AF476` (`terminal_id`),
KEY `FK1C2451BAD08942D5` (`application_version_id`),
CONSTRAINT `FK1C2451BA760AF476` FOREIGN KEY (`terminal_id`) REFERENCES `m_terminal` (`id`),
CONSTRAINT `FK1C2451BAD08942D5` FOREIGN KEY (`application_version_id`) REFERENCES `m_application_version` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=56 DEFAULT CHARSET=utf8;
副表:终端表
CREATE TABLE `m_terminal` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;
------------------------------------------------------------------------------------
RTerminalApplication.java中配置
@Entity
@Table(name = "R_TERMINAL_APPLICATION")
public class RTerminalApplication extends BaseModel {
private MTerminal terminal;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "TERMINAL_ID", nullable = false)
//在这里使用cascade的话,是删除关系表数据时触发同时删除终端,我想要相反的效果
public MTerminal getTerminal() {
return terminal;
}
}
------------------------------------------------------------------------------------
终端表与终端应用关系表的对应应该是一对多吧,怎样实现删除一个终端时,级联删除关系表里面维护的这几条数据呢? hibernate sql j2ee 级联删除
补充:Java , Java EE