[hibernate-dev] Statements issued for unidirectional one-to-many with @JoinColumn

Gunnar Morling gunnar at hibernate.org
Thu Jan 21 06:25:04 EST 2016


Steve, all,

I have a model with two entities, Parent and Child, and an
unidirectional one-to-many association from the former to the latter.

Via @JoinColumn on the association it is ensured that the Parent FK is
stored in the Child table, i.e. without a separate join table. When
inserting a Parent and several Child entities, I see the following
statements:

    INSERT INTO parent (id, name) VALUES (?,?)

    INSERT INTO child (id, childname) VALUES (?,?)
    INSERT INTO child (id, childname) values (?,?)

    UPDATE CHILD SET Parent_id=? WHERE id=?
    UPDATE CHILD SET Parent_id=? WHERE id=?

Why is it that the FK is propagated through separate updates instead
of doing it as part of the Child insert?

Thanks,

--Gunnar


More information about the hibernate-dev mailing list