gpt4 book ai didi

java - 当我尝试插入通知类型对象时,子实体也会尝试插入

转载 作者:行者123 更新时间:2023-11-29 10:32:15 25 4
gpt4 key购买 nike

我有一个 notificationTypes 表、权限表。这些是通过桥接表 notification_types_permission 链接的。当所有实体都是新的时,它就可以正常工作。我的问题是,当我尝试使用现有权限插入新的 notificationTypes 时,该权限也会尝试插入新的 notificationTypes 。我的表和实体结构如下所示。

 CREATE TABLE `notification_types` (
`Id` BIGINT(16) NOT NULL AUTO_INCREMENT,
`TypeName` VARCHAR(80) NOT NULL,
`InsertedDttm` DATETIME NULL,
`InsertedBy` BIGINT(16) NULL,
`UpdatedDttm` DATETIME NULL,
`UpdatedBy` BIGINT(16) NULL,
PRIMARY KEY (`Id`));

CREATE TABLE `notification_types_permission` (
`Id` BIGINT(16) NOT NULL AUTO_INCREMENT,
`NotificationTypes_ID` BIGINT(16) NOT NULL,
`permissions_ID` int(11) NOT NULL,
PRIMARY KEY (`Id`), FOREIGN KEY (NotificationTypes_ID)
REFERENCES `frontoffice`.notification_types(id), FOREIGN KEY (permission_Id)
REFERENCES `frontoffice`.`permission`(id));
public class NotificationTypes {

@Id
private Long id;
private String typeName;
@Temporal(TemporalType.TIMESTAMP)
private Date insertedDttm;
private Long insertedBy;
@Temporal(TemporalType.TIMESTAMP)
private Date updatedDttm;
private Long updatedBy;

@OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
private List<RLPermissions> permissions;
}

最佳答案

 @OneToMany( fetch = FetchType.EAGER)
private List<RLPermissions> permissions;

如果不需要对权限列表进行删除、更新和插入操作,请避免该关系中的级联属性。

关于java - 当我尝试插入通知类型对象时,子实体也会尝试插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47182612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com