Hibernate: Partial lazy initialization?

I have a many-to-many association defined as:

Parent.hbm.xml:

    <set name="children" table="child_parent_map" lazy="true">
        <cache usage="nonstrict-read-write" />
        <key column="parent_id" />
        <many-to-many class="Child">
            <column name="child_id" not-null="true" index="child_parent_by_child"/>
        </many-to-many>
    </set>

Child.hbm.xml:

    <set name="parents" table="child_parent_map" lazy="true">
        <cache usage="nonstrict-read-write" />
        <key column="child_id" />
        <many-to-many column="parent_id" class="Parent"  lazy="false"/>
    </set>

I am sure that I initialize Parent.childrenthrough the collection. Sort of:

for(Child child : parent.getChildren()) {
    Hibernate.initialize(child.getAnotherProperty());
}

The parent has six children. However, in one session, the parent server has only five, and in the other (after 2 seconds, nothing has changed in the database or in another session) - all six. In fact, I discovered this after disconnecting these objects from the session using a custom cloner.

I thought that lazy collections are either fully initialized (i.e. all elements) or not. Is it possible that some part of the collection was initialized? Could this be a cache problem?

EDIT. ( ). , , ?

+3
1

hashCode() equals(), .

+1

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


All Articles