为什么orphanRemoval = true对我不起作用?

时间:2018-07-31 22:11:09

标签: spring-boot spring-data-jpa many-to-one

背景

我在Spring Boot应用程序中有两个实体。一个称为#:kivy 1.11.0 <SelectableButton>: # Draw a background to indicate selection canvas.before: Color: rgba: (.0, 0.9, .1, .3) if self.selected else (0, 0, 0, 1) Rectangle: pos: self.pos size: self.size on_press: app.root.screen_two.populate_fields(self) <ScreenTwo>: user_no_text_input: no user_name_text_input: name image: image AccordionItem: title: "INPUT FIELDS" GridLayout: rows:3 BoxLayout: size_hint: .5, None height: 600 pos_hint: {'center_x': 1} padding: 10 spacing: 3 orientation: "vertical" Label: text: "Employee ID" size_hint: (.5, None) height: 30 TextInput: id: no size_hint: (.5, None) height: 30 multiline: False Label: text: "Employee NAME" size_hint: (.5, None) height: 30 TextInput: id: name size_hint: (.5, None) height: 30 multiline: False Label: text: "Employee PHOTO" size_hint: (.5, None) height: 30 Image: id: image allow_stretch: True keep_ratio: True Button: text: "SELECT IMAGE" size_hint_y: None height: self.parent.height * 0.2 on_release: root.filechooser() Button: id: save_btn text: "SAVE BUTTON" height: 50 on_press: root.save() AccordionItem: title: "RECYCLE VIEW" BoxLayout: orientation: "vertical" GridLayout: size_hint: 1, None size_hint_y: None height: 25 cols: 2 Label: text: "Employee ID" Label: text: "Employee Name" # Display only the first two columns Employee ID and Employee Name NOT EmployeePhoto on the RecycleView BoxLayout: RecycleView: viewclass: 'SelectableButton' data: root.data_items SelectableRecycleGridLayout: cols: 2 default_size: None, dp(26) default_size_hint: 1, None size_hint_y: None height: self.minimum_height orientation: 'vertical' multiselect: True touch_multiselect: True Button: text: "On Screen 2 >> Go to Screen 1" on_press: root.manager.current = 'screen1' ,其中包含有关一段时间的乐器的元数据。另一个称为visit,它反映了在访问期间该仪器是如何连接的。

在数据库中,visit.attachment_id是附件的可为空的外键。多次访问可以引用相同的附件记录,但是一次访问根本不需要引用附件。数据库中存在任何访问未引用的孤立孤岛附件记录。

访问实体

attachment

附件实体

//Imports...

@Entity
@Data
@SequenceGenerator(name = "visit_seq_gen", sequenceName = "visit_seq", allocationSize = 1)
@Table(name = "VISIT")
public class Visit implements Serializable {

    @Id
    @GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "visit_seq_gen" )
    @Column(name = "VISIT_ID")
    private Long visitId;

    //Other fields...

    @ManyToOne( fetch=FetchType.LAZY, cascade=CascadeType.ALL )
    @JoinColumn(name = "ATTACHMENT_ID")
    private Attachment attachment;

}

问题

每次我更新现有的访问记录时,都会创建一个新的附件记录。尽管有//Imports... @Entity @Data @SequenceGenerator(name = "attachment_seq_gen", sequenceName = "attachment_seq", allocationSize = 1) @Table(name = "ATTACHMENT") public class Attachment implements Serializable { @Id @GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "attachment_seq_gen" ) @Column(name = "ATTACHMENT_ID") private Long attachmentId; //Other fields... @JsonIgnore @OneToMany(mappedBy="attachment", orphanRemoval=true) private Set<Visit> visitSet; } ,仍未删除旧的附件记录。有什么想法吗?

0 个答案:

没有答案