Hibernation: composite element deletes + insert at each commit

Here is part of my mapping:

<hibernate-mapping package="trx.domain">
    <class name="Master" table="master" dynamic-update="true" dynamic-insert="true">

        <set name="attributes" table="attribute" lazy="true"
            cascade="all" batch-size="10">
            <cache usage="nonstrict-read-write" />
            <key>
                <column name="master_id" />
            </key>
            <composite-element class="Attribute">
                <many-to-one name="type" class="AttributeType"
                     not-null="true" column="attribute_type_id" lazy="false" />
                <property name="value">
                    <column name="value" />
                </property>
            </composite-element>
        </set>
    </class>
</hibernate-mapping>

If I simply scan a set attributeswithout any updates, Hibernate will still perform a package of operations deleteand insertcommit.

Hibernate: delete from attribute where master_id=? and attribute_type_id=?
Hibernate: delete from attribute where master_id=? and attribute_type_id=?
Hibernate: insert into attribute (master_id, attribute_type_id, value) values (?, ?, ?)
Hibernate: insert into attribute (master_id, attribute_type_id, value) values (?, ?, ?)

Why is this happening? How to prevent this?

+3
source share
1 answer

According to Hibernate Reference

Due to the structure of the set, Hibernate does NOT UPDATE the line when the item is "modified." Changes to a set always work through INSERT and DELETE from separate lines.

Hibernate , , , equals hashcode Attribute ?

+4

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


All Articles