I have a mapped object that has collection of another mapped objects. Whenever an object in the contained collection is new for the DB, I have an insertion behaviour with consequent update.
My questions are:
- What is the purpose of this secondary update?
- How can I listen to it?
Adding a PreUpdateEventListener does not work.
What I want to do it is to eliminate this secondary update to the same values and get it done by single insertion only.
I've found such a question here: https://forum.hibernate.org/viewtopic.php?f=1&t=1011641 but there is no answer.
Also I've found there is a flag "update", it seems does the trick but is that a reason of described behaviour?
Mapping:
<class>
...
<map name="attributes" table="DEF"
cascade="all-delete-orphan" lazy="false" batch-size="5">
<key not-null="true">
<column name="PID"/>
<column name="CDATE"/>
</key>
<map-key column="NAME" type="string" alias="name"/>
<one-to-many entity-name="DocumentAttributes"/>
</map>
...
<class>
<class name="com.moc.Attribute"
entity-name="DocumentAttributes" table="DEF"
dynamic-update="true"
dynamic-insert="true">..</class>
Hibernate logs:
Hibernate: insert into BDOC (ID, CDATE) values (?, ?)
// Why this insertion consists all columns despite being dynamic?
Hibernate: insert into DEF (TYPE, VALUE, IS_CHANGED, PID, CDATE, NAME, id) values (?, ?, ?, ?, ?, ?, ?)
//Why this update happen??
Hibernate: update DEF set PID=?, CDATE=?, NAME=? where id=?
Is anyone here who can describe such behaviour?