我想通过entityManager.persist(myEntity)
将实体bellow保存到数据库。但是,孩子的(ProjectEntity
)孩子也会更新。如何禁用子实体更新的更新。
谢谢。
@Entity
@Table(name = "my_entity")
public class MyEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Integer id;
@Column
private String user;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "project_id")
private ProjectEntity project;
}
答案 0 :(得分:0)
请在您的实体中更新以下代码
@ManyToOne(fetch = FetchType.LAZY,orphanRemoval=true)
@JoinColumn(name = "project_id")
private ProjectEntity project;