如何在使用JPA创建表时添加 ON DELETE SET NULL ON UPDATE SET NULL 约束。在实体定义下面
表
CREATE TABLE `node` (
`id` bigint(20) NOT NULL,
`parentNode_id` bigint(20) default NULL,
PRIMARY KEY (`id`),
KEY `FK1EC1DD0F28AB6BA5` (`parentNode_id`),
CONSTRAINT `FK1EC1DD0F28AB6BA5` FOREIGN KEY (`parentNode_id`) REFERENCES `node` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
@Entity
public class Node {
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "NodeSequence")
private long id;
@ManyToOne(cascade=CascadeType.REMOVE)
@JoinColumn(name = "parentNode_id", nullable = true)
protected Node parentNode = null;
}