I have the following entities in a one-to-many relationship:
@Entry
class Parent {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private int id;
...
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
private Collection<Child> children;
...
}
and
@Entry
class Child {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private int id;
...
@Transient
private Parent parent;
...
}
So – out of these, there are the following 2 entity tables in the database
parent(id, ...)
child(id, ..)
and the relationship table between these two entities-- due to that @OneToMany
relationship
parent_child(parent_id, child_id)
suppose parent_id=4
has the child_id=7
and thus parent_child
table has the row (parent_id=4, child_id=7)
.
When i delete child id =7, isn’t the (parent_id=4, child_id=7)
in parent_child
table supposed to be deleted as part of it? I’m seeing that row in parent_child
table even after the corresponding child is deleted from the child table.
I’m using the repository (implementing CrudRepository
) for deleting that child.
//////////////
UPDATE:
by parent_child(parent_id, child_id)
, i'm referring to the relationship table that hibernate is generating behind the scenes to maintain the relationship between parent
and child
tables.
went into this table out of curiosity directly on SQL. and these are what i'm seeing. i expected (still do) the (parent_id=4, child_id=7)
row would disappear now that child_id=7
fell off the face of the Earth. but didn't.