Merge in jpa many-to-many with extra column in join table

I have a many-to-many relationship with three tables and entities, and the join table contains an extra column. On both sides of the relationship, I have set cascadeType.All When I add new objects on the owner side, the merge method works fine, but when I remove the child object from the owner and merge it, the corresponding rows in the join table will not be deleted and I will have duplicate rows ...

owner

    @OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "definitionType")
    private List<DefinitionProperty> definitionProperties = new ArrayList<DefinitionProperty>();

      


    @OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "property")  
    private List<DefinitionProperty> definitionProperties= new ArrayList<DefinitionProperty>();

      


mapping object

    @Id
    @JoinColumn(name = "dtid", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private DefinitionType definitionType;

    @Id
    @JoinColumn(name = "prid", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Property property;

      

I am not calling the delete method of my entity manager at all and I expect the cascade to automatically delete unneeded lines. Is it possible? what should i do to remove these lines? I can add my code here if it helps

+3


source to share


1 answer


It just needed orphanRemoval = true on the owner's side.



0


source







All Articles