Why does hibernate delete rows from the connection table when adding an item to set the display to many-to-many?

Suposse I have two classes:

class A {
Set<B> bs
}
class B {
}

This mapping is:

<set name="bs" table="bs_tab" cascade = "save-update">
            <key column="a_id />
            <many-to-many column="b_id" class="B"/>
</set>

And join the table as follows:

bs_tab(
a_id, b_id, primary key(a_id, b_id)
)

When I add some element to bs set and then call Session.saveOrUpdate (instance) sleep mode, it deletes all the rows in bs_tab, corresponding to the B instances that were in the set, before adding a new element.

How can i solve this?

+3
source share
1 answer

, equals/hashCode. ( --), DELETE, INSERT SQL- .

+3

Source: https://habr.com/ru/post/1772362/


All Articles