0
public class A implements Serializable {
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
@JoinColumn(name = "A_ID")
private List<B> bList;
}
public class B implements Serializable {
@JoinColumn(name = "A_ID", referencedColumnName = "ID")
@ManyToOne(optional = false)
private A a;
}
With a lot of cost I managed to get Hibernate to leave the Foreign key of table A inside B as null in a register update, but with orphanRemoval = true it should delete these records from table B, which is not happening. How to solve this problem?
When you carry the
Object A
to be deleted, the variableList<B>
is it filled? I wonder why theFetchType.LAZY
causes the list to be loaded only if it is accessed.– Paulo H. Hartmann
Airton, can you pass which error you generate? Or if you are able to delete item A and item B is orphaned?
– Gonzaga Neto
The LSITA is loaded straight including Hibernate until it leaves the foregin Keys of table B as null, but it does not delete these lines.... it simply leaves nullas and does not erase them
– airton
When using the Eclipse link only needed by @Privateowned q he already did all this... however agr in Hibernate I’m catching a little
– airton
Try to map only one side with
@JoinColumn
(the side that has the foreign key) and the other use themappedBy
. The way it is there, there’s no dominant side to the relationship and the Hibernant may be getting lost.– StatelessDev
previously table A had mappedby on @Onetomany, and table B had joinColumn, but this way it was not even setting null to Foreign key of table B when saving the object of table A
– airton
I realized q if I remove the Cascadetype.All and put only the Cascadetype.Persist and the Cascadetype.Remove it starts to remove correctly. However I still need Cascadetype.Merge and that’s where the problem arises. If I put Cascadetype.Merge, the removal of the items stops working
– airton
I set up the same structure in a desktop project only with Hibernate and my current project uses springboot. In desktop design works perfectly, in problem springboot project
– airton