<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> 
        <base href="https://hibernate.atlassian.net"> 
        <title>Message Title</title> 
    </head> 
    <body class="jira" style="color: #333333; font-family: Arial, sans-serif; font-size: 14px; line-height: 1.429"> 
        <table id="background-table" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; background-color: #f5f5f5; border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0" bgcolor="#f5f5f5"> 
            <!-- header here --> 
            <tbody>
                <tr> 
                    <td id="header-pattern-container" style="padding: 0; border-collapse: collapse; padding: 10px 20px"> 
                        <table id="header-pattern" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                            <tbody>
                                <tr> 
                                    <td id="header-avatar-image-container" valign="top" style="padding: 0; border-collapse: collapse; vertical-align: top; width: 32px; padding-right: 8px" width="32"> <img id="header-avatar-image" class="image_fix" src="https://avatar-cdn.atlassian.com/7f425011c5c2a0756ec2b97b778bd900?s=48&amp;d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F7f425011c5c2a0756ec2b97b778bd900%3Fd%3Dmm%26s%3D48%26noRedirect%3Dtrue" height="32" width="32" border="0" style="border-radius: 3px; vertical-align: top"> </td> 
                                    <td id="header-text-container" valign="middle" style="padding: 0; border-collapse: collapse; vertical-align: middle; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> <a class="user-hover" rel="marc.hanggi" id="email_marc.hanggi" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=marc.hanggi" style="color:#6c797f;; color: #3b73af; text-decoration: none">Marc Hanggi</a> <strong>updated</strong> an issue </td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
                <tr> 
                    <td id="email-content-container" style="padding: 0; border-collapse: collapse; padding: 0 20px"> 
                        <table id="email-content-table" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; border-spacing: 0; border-collapse: separate"> 
                            <tbody>
                                <tr> 
                                    <!-- there needs to be content in the cell for it to render in some clients --> 
                                    <td class="email-content-rounded-top mobile-expand" style="padding: 0; border-collapse: collapse; color: #ffffff; padding: 0 15px 0 16px; height: 15px; background-color: #ffffff; border-left: 1px solid #cccccc; border-top: 1px solid #cccccc; border-right: 1px solid #cccccc; border-bottom: 0; border-top-right-radius: 5px; border-top-left-radius: 5px; height: 10px; line-height: 10px; padding: 0 15px 0 16px; mso-line-height-rule: exactly" height="10" bgcolor="#ffffff">&nbsp;</td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand " style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff" bgcolor="#ffffff"> 
                                        <table class="page-title-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                            <tbody>
                                                <tr> 
                                                    <td class="page-title-pattern-first-line " style="padding: 0; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; padding-top: 10px"> <a href="https://hibernate.atlassian.net/browse/HHH" style="color: #3b73af; text-decoration: none">Hibernate ORM</a> / <a href="https://hibernate.atlassian.net/browse/HHH-11991" style="color: #3b73af; text-decoration: none"><img src="cid:jira-generated-image-avatar-8afcfa2f-496a-4952-9ce0-84f088aba6a2" height="16" width="16" border="0" align="absmiddle" alt="Bug" style="vertical-align: text-bottom"></a> <a href="https://hibernate.atlassian.net/browse/HHH-11991" style="color: #3b73af; text-decoration: none">HHH-11991</a> </td> 
                                                </tr> 
                                                <tr> 
                                                    <td style="vertical-align: top;; padding: 0; border-collapse: collapse; padding-right: 5px; font-size: 20px; line-height: 30px; mso-line-height-rule: exactly" class="page-title-pattern-header-container"> <span class="page-title-pattern-header" style="font-family: Arial, sans-serif; padding: 0; font-size: 20px; line-height: 30px; mso-text-raise: 2px; mso-line-height-rule: exactly; vertical-align: middle"> <a href="https://hibernate.atlassian.net/browse/HHH-11991" style="color: #3b73af; text-decoration: none">Unnecessary sql updates are triggerd for all elements in map</a> </span> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand  wrapper-special-margin" style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff; padding-top: 10px; padding-bottom: 5px" bgcolor="#ffffff"> 
                                        <table class="keyvalue-table" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                            <tbody>
                                                <tr> 
                                                    <th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">Change By:</th> 
                                                    <td style="padding: 0; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top"> <a class="user-hover" rel="marc.hanggi" id="email_marc.hanggi" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=marc.hanggi" style="color:#6c797f;; color: #3b73af; text-decoration: none">Marc Hanggi</a> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand  issue-description-container" style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff; padding-top: 5px; padding-bottom: 10px" bgcolor="#ffffff"> 
                                        <table class="text-paragraph-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 2px"> 
                                            <tbody>
                                                <tr> 
                                                    <td class="text-paragraph-pattern-container mobile-resize-text " style="padding: 0; border-collapse: collapse; padding: 0 0 10px"> <span class="diffcontext">Dear Hibernate Developers<br><br>[I have already talked to Vlad about this problem|https://forum.hibernate.org/viewtopic.php?f=1&amp;t=1044827&amp;p=2493417#p2493417]<br><br>Hibernate triggers unnecessary update statements for all previous elements of a map if a new element is being added to this map. The problem only occures for maps with bidirectional bindings and HBM XML mappings. I was unable to reproduce the issue with annotation based mappings or unidirectional bindings.<br><br>I built a simple demo projects containing two classes for illustration purposes. A person object referencing one or more task objects.<br><br><br>Person.hbm.xml<br>{code:xml}<br>&lt;hibernate-mapping&gt;<br>&nbsp; &nbsp; &lt;class name="persistency.test.Person" table="person" lazy="true"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;id name="dbKey" type="long" access="field" column="dbkey"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;generator class="native" /&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/id&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;property name="name" type="java.lang.String" length="20" access="field" /&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;map name="tasks" cascade="all-delete-orphan" inverse="true" access="field"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;key column="person_dbkey" /&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;map-key type="string" column="name" /&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;one-to-many class="persistency.test.Task" /&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/map&gt;<br>&nbsp; &nbsp; &lt;/class&gt;<br>&lt;/hibernate-mapping&gt;<br>{code}<br><br><br>Person.java<br>{code:java}<br>public class Person {<br><br>&nbsp; &nbsp; private String name;<br>&nbsp; &nbsp; private long dbKey;<br><br>&nbsp; &nbsp; private Map&lt;String, Task&gt; tasks = new HashMap&lt;&gt;();<br><br>&nbsp; &nbsp; public void addTask(Task task) {<br>&nbsp; &nbsp; &nbsp; &nbsp; task.setOwner(this);<br>&nbsp; &nbsp; &nbsp; &nbsp; this.tasks.put(task.getName(), task);<br>&nbsp; &nbsp; }<br>}<br>{code}<br><br><br>Task.hbm.xml<br>{code:xml}<br>&lt;hibernate-mapping&gt;<br>&nbsp; &nbsp; &lt;class name="persistency.test.Task" table="task" lazy="true"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;id name="dbKey" type="long" access="field" column="dbkey"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;generator class="native" /&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/id&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;property name="name" type="java.lang.String" length="20" access="field" /&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;property name="description" type="java.lang.String" length="100" access="field" /&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;many-to-one name="owner" column="person_dbkey" class="persistency.test.Person" access="field" /&gt;<br><br>&nbsp; &nbsp; &lt;/class&gt;<br>&lt;/hibernate-mapping&gt;{code}<br><br><br>Task.java<br>{code:java}<br>public class Task {<br><br>&nbsp; &nbsp; private String name;<br>&nbsp; &nbsp; private long dbKey;<br>&nbsp; &nbsp; private Person owner;<br>&nbsp; &nbsp; private String description;<br><br>&nbsp; &nbsp; public Task(String name, String description) {<br>&nbsp; &nbsp; &nbsp; &nbsp; this.name = name;<br>&nbsp; &nbsp; &nbsp; &nbsp; this.description = description;<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp; public Task() { }<br><br>&nbsp; &nbsp; public String getName() {<br>&nbsp; &nbsp; &nbsp; &nbsp; return name;<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp; public void setOwner(Person owner) {<br>&nbsp; &nbsp; &nbsp; &nbsp; this.owner = owner;<br>&nbsp; &nbsp; }<br>}<br>{code}<br><br>The table Task already contains three tasks:<br>{noformat}<br>DBKEY&nbsp; | NAME&nbsp; &nbsp; &nbsp;| PERSON_DBKEY&nbsp; | DESCRIPTION<br>221000 | Eating&nbsp; &nbsp;| 139000&nbsp; &nbsp; &nbsp; &nbsp; | Food<br>218000 | Cooking&nbsp; | 139000&nbsp; &nbsp; &nbsp; &nbsp; | Food<br>225000 | Reading&nbsp; | 139000&nbsp; &nbsp; &nbsp; &nbsp; | Food <br>{noformat}<br><br>If a new task is being added to the map containg already three tasks:<br>{code:java}<br>session.beginTransaction();<br>Person person = session.load(Person.class, 139000l);<br>person.addTask(new Task("Cleaning", "Floor, Roof"));<br><br>session.getTransaction().commit();<br>{code}<br><br>Hibernate then executes the following SQL statements:<br><br>{code:sql}<br>select person0_.dbkey as dbkey1_0_0_, person0_.name as name2_0_0_ from XHM_2.person person0_ where person0_.dbkey=?<br>select tasks0_.person_dbkey as person_dbkey4_1_0_, tasks0_.dbkey as dbkey1_1_0_, tasks0_.name as name2_0_, tasks0_.dbkey as dbkey1_1_1_, tasks0_.name as name2_1_1_, tasks0_.description as description3_1_1_, tasks0_.person_dbkey as person_dbkey4_1_1_ from XHM_2.task tasks0_ where tasks0_.person_dbkey=?<br><br>select XHM_2.hibernate_sequence.nextval from dual<br>insert into XHM_2.task (name, description, person_dbkey, dbkey) values ('Cleaning', 'Floor, Roof', '139000', '224000')<br>update XHM_2.task set name='Eating' where dbkey='221000'<br>update XHM_2.task set name='Cooking' where dbkey='218000'<br>update XHM_2.task set name='Reading' where dbkey='225000'<br>update XHM_2.task set name='Cleaning' where dbkey='224000'<br>{code}<br><br>Hibernate triggers</span> <span class="diffremovedchars" style="background-color: #ffe7e7; text-decoration:line-through;"> for</span> <span class="diffaddedchars" style="background-color:#ddfade;"> four</span> <span class="diffcontext"> update statements as shown above. I think there is no reason to update the previous three elements and the newly added element either.</span> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand " style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff" bgcolor="#ffffff"> <script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "EmailMessage",
  "description": "View Issue",
  "potentialAction": {
    "@type": "ViewAction",
        "target": "https://hibernate.atlassian.net/browse/HHH-11991?inbox=true&",
    "name": "View Issue"
      },
  "publisher": {
    "@type": "Organization",
    "name": "Atlassian",
    "url": "https://www.atlassian.com"
  }
}
</script> 
                                        <table id="actions-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> 
                                            <tbody>
                                                <tr> 
                                                    <td id="actions-pattern-container" valign="middle" style="padding: 0; border-collapse: collapse; padding: 10px 0 10px 24px; vertical-align: middle; padding-left: 0"> 
                                                        <table align="left" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                                            <tbody>
                                                                <tr> 
                                                                    <td class="actions-pattern-action-icon-container" style="padding: 0; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 0; vertical-align: middle"> <a href="https://hibernate.atlassian.net/browse/HHH-11991#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none"> <img class="actions-pattern-action-icon-image" src="cid:jira-generated-image-static-comment-icon-1ee17f54-4b64-4f92-929e-42a944cefd68" alt="Add Comment" title="Add Comment" height="16" width="16" border="0" style="vertical-align: middle"> </a> </td> 
                                                                    <td class="actions-pattern-action-text-container" style="padding: 0; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 4px; padding-left: 5px"> <a href="https://hibernate.atlassian.net/browse/HHH-11991#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none">Add Comment</a> </td> 
                                                                </tr> 
                                                            </tbody>
                                                        </table> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <!-- there needs to be content in the cell for it to render in some clients --> 
                                <tr> 
                                    <td class="email-content-rounded-bottom mobile-expand" style="padding: 0; border-collapse: collapse; color: #ffffff; padding: 0 15px 0 16px; height: 5px; line-height: 5px; background-color: #ffffff; border-top: 0; border-left: 1px solid #cccccc; border-bottom: 1px solid #cccccc; border-right: 1px solid #cccccc; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; mso-line-height-rule: exactly" height="5" bgcolor="#ffffff">&nbsp;</td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
                <tr> 
                    <td id="footer-pattern" style="padding: 0; border-collapse: collapse; padding: 12px 20px"> 
                        <table id="footer-pattern-container" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                            <tbody>
                                <tr> 
                                    <td id="footer-pattern-mobile-separated-links" class="mobile-resize-text" width="100%" colspan="2" style="padding: 0; border-collapse: collapse; color: #999999; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px"> Get JIRA notifications on your phone! Download the JIRA Cloud app for <a href="https://play.google.com/store/apps/details?id=com.atlassian.android.jira.core&amp;referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail" style="color: #3b73af; text-decoration: none">Android</a> or <a href="https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&amp;ct=EmailNotificationLink&amp;mt=8" style="color: #3b73af; text-decoration: none">iOS</a> 
                                        <hr> </td> 
                                </tr> 
                                <tr> 
                                    <td id="footer-pattern-text" class="mobile-resize-text" width="100%" style="padding: 0; border-collapse: collapse; color: #999999; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px"> This message was sent by Atlassian Jira <span id="footer-build-information">(v1000.1263.0#100059-<span title="d0fd8ce4291fe8b6dd1964e19a583ba501ef6147" data-commit-id="d0fd8ce4291fe8b6dd1964e19a583ba501ef6147}">sha1:d0fd8ce</span>)</span> </td> 
                                    <td id="footer-pattern-logo-desktop-container" valign="top" style="padding: 0; border-collapse: collapse; padding-left: 20px; vertical-align: top"> 
                                        <table style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                            <tbody>
                                                <tr> 
                                                    <td id="footer-pattern-logo-desktop-padding" style="padding: 0; border-collapse: collapse; padding-top: 3px"> <img id="footer-pattern-logo-desktop" src="cid:jira-generated-image-static-footer-desktop-logo-03eabb25-b1f0-4716-9783-c32f53dc5645" alt="Atlassian logo" title="Atlassian logo" width="192" height="24" class="image_fix"> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
            </tbody>
        </table>   
    </body>
</html>