Java 如何使用Spring数据JPA更新子列表?
我有一个“编辑非”页面,用户可以添加或删除NotRecipient 问题是,当我保存编辑的Not对象时,它会将编辑的NotRecipients保存为新对象。我要做的是在保存Not object check NotRecipients name字段以更新或添加新内容时。有没有办法做到这一点Java 如何使用Spring数据JPA更新子列表?,java,jpa,spring-data,Java,Jpa,Spring Data,我有一个“编辑非”页面,用户可以添加或删除NotRecipient 问题是,当我保存编辑的Not对象时,它会将编辑的NotRecipients保存为新对象。我要做的是在保存Not object check NotRecipients name字段以更新或添加新内容时。有没有办法做到这一点 @Entity @Table(name = "not") public class Not implements Serializable{ @Id @Column(name = "not_id")
@Entity
@Table(name = "not")
public class Not implements Serializable{
@Id
@Column(name = "not_id")
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "org.hibernate.id.UUIDGenerator")
private String notId;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "not", fetch = FetchType.EAGER)
private List<NotRecipient> recipients = new ArrayList<>();
//getters and setters
}
@Entity
@Table(name = "not_reciepent")
public class NotRecipient implements Serializable {
@Id
@Column(name = "not_recipient_id")
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "org.hibernate.id.UUIDGenerator")
private String notRecipientId;
@JsonIgnore
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "not_id")
private Not not;
@Column
private String name;
//getters and setters
}
@实体
@表(name=“not”)
公共类未实现可序列化{
@身份证
@列(name=“not_id”)
@GeneratedValue(generator=“系统uuid”)
@GenericGenerator(name=“system uuid”,strategy=“org.hibernate.id.UUIDGenerator”)
私有字符串notId;
@OneToMany(cascade=CascadeType.ALL,mappedBy=“not”,fetch=FetchType.EAGER)
私有列表收件人=新建ArrayList();
//接球手和接球手
}
@实体
@表(name=“未接收”)
公共类NotRecipient实现可序列化{
@身份证
@列(name=“not\u recipient\u id”)
@GeneratedValue(generator=“系统uuid”)
@GenericGenerator(name=“system uuid”,strategy=“org.hibernate.id.UUIDGenerator”)
私有字符串notRecipientId;
@杰索尼奥雷
@manytone(fetch=FetchType.LAZY)
@JoinColumn(name=“not_id”)
私不可私;
@纵队
私有字符串名称;
//接球手和接球手
}
如何加载和保存实体?您的事务是如何界定范围的?