<!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://secure.gravatar.com/avatar/a2f1c36aac35e43a94fe67a0436b81bc?d=mm&amp;s=48" 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="ccasey" id="email_ccasey" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=ccasey" style="color:#6c797f;; color: #3b73af; text-decoration: none">Cliff Casey</a> <strong>created</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-11648" style="color: #3b73af; text-decoration: none"><img src="cid:jira-generated-image-avatar-27fba8bc-8a82-475d-b785-11eaf0cb555b" height="16" width="16" border="0" align="absmiddle" alt="Bug" style="vertical-align: text-bottom"></a> <a href="https://hibernate.atlassian.net/browse/HHH-11648" style="color: #3b73af; text-decoration: none">HHH-11648</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-11648" style="color: #3b73af; text-decoration: none">Hibernate Soft Delete on Many to Many Creating Strange Query on Find</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">Issue Type:</th> 
                                                    <td class="has-icon" style="padding: 0; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top"> <img src="cid:jira-generated-image-avatar-27fba8bc-8a82-475d-b785-11eaf0cb555b" height="16" width="16" border="0" align="absmiddle" alt="Bug" style="vertical-align: text-bottom"> Bug </td> 
                                                </tr> 
                                                <tr> 
                                                    <th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">Affects Versions:</th> 
                                                    <td style="padding: 0; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top"> 5.2.5 </td> 
                                                </tr> 
                                                <tr> 
                                                    <th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">Assignee:</th> 
                                                    <td style="padding: 0; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top"> Unassigned </td> 
                                                </tr> 
                                                <tr> 
                                                    <th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">Components:</th> 
                                                    <td style="padding: 0; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top"> hibernate-core, hibernate-entitymanager, query-hql, query-sql </td> 
                                                </tr> 
                                                <tr> 
                                                    <th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">Created:</th> 
                                                    <td style="padding: 0; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top"> 19/Apr/2017 12:17 PM </td> 
                                                </tr> 
                                                <tr> 
                                                    <th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">Environment:</th> 
                                                    <td style="padding: 0; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top"> Java 8 <br> Spring 4.3.3 <br> Hibernate 5.2.5 Final </td> 
                                                </tr> 
                                                <tr> 
                                                    <th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">Priority:</th> 
                                                    <td class="has-icon" style="padding: 0; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top"> <img src="cid:jira-generated-image-static-major-a19563c3-9fdc-4ebd-80e4-122c74db08bf" height="16" width="16" border="0" align="absmiddle" alt="Major" style="vertical-align: text-bottom"> Major </td> 
                                                </tr> 
                                                <tr> 
                                                    <th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">Reporter:</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="ccasey" id="email_ccasey" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=ccasey" style="color:#6c797f;; color: #3b73af; text-decoration: none">Cliff Casey</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"> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0; margin-top: 0">I am trying to implement annotation based soft delete in hibernate, in this case on a many-to-many relationship. Up until now it has worked very well, but I encountered an odd condition that I am wondering if it's a bug or I am simply misinterpreting the usage.</p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">The problem comes when I try to execute a find on an entity (A) and the soft-delete-where for the child (B) is injected to the overall where for the base entity in the actual SQL output of the find. The end result of this is if the A does not have any Bs, the soft-delete-where causes the main find query to return no As, even if they exist.</p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">Here is an example of the annotations used in A (simplified for readability):</p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">@Entity<br> @SQLDelete(sql = "UPDATE List SET isActive = 0 WHERE id = ? AND version = ?")<br> @Where(clause = "isActive = 1")<br> public class List extends AbstractEntity </p> { @ManyToMany(fetch=FetchType.EAGER) @JoinTable(name="ListAuthGroup", joinColumns=@JoinColumn(name="listId"), inverseJoinColumns=@JoinColumn(name="authGroupId")) private Set&lt;AuthGroup&gt; authGroups = new HashSet&lt;AuthGroup&gt;(); } <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">And here are the annotations used in B (also simplified for readability):</p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">@Entity<br> @SQLDelete(sql = "UPDATE AuthGroup SET isActive = 0 WHERE id = ? AND version = ?")<br> @Where(clause = "isActive = 1")<br> public class AuthGroup extends AbstractEntity {</p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0"> @ManyToMany(cascade = </p> { CascadeType.ALL } <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">, mappedBy = "authGroups")<br> @JsonIgnore<br> private Set&lt;List&gt; lists = new HashSet&lt;List&gt;();<br> }</p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">Here is the SQL output from logs from a simple getSession().get(List.class, id);</p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">select list0_.id as id1_13_0_, list0_.createdAt as createdA2_13_0_, list0_.createdBy as createdB3_13_0_, list0_.isActive as isActive4_13_0_, list0_.modifiedAt as modified5_13_0_, list0_.updatedBy as updatedB6_13_0_, list0_.version as version7_13_0_, list0_.bounceLimit as bounceLi8_13_0_, list0_.code as code9_13_0_, list0_.defaultFrom as default10_13_0_, list0_.description as descrip11_13_0_, list0_.listType as listTyp12_13_0_, list0_.name as name13_13_0_, list0_.owningOrgId as owningO20_13_0_, list0_.seed as seed14_13_0_, list0_.seedThreshold as seedThr15_13_0_, list0_.sendingDomain as sending16_13_0_, list0_.trackerDomain as tracker17_13_0_, list0_.unsubDomain as unsubDo18_13_0_, list0_.xBinding as xBindin19_13_0_, authgroups1_.listId as listId1_14_1_, authgroup2_.id as authGrou2_14_1_, authgroup2_.id as id1_2_2_, authgroup2_.createdAt as createdA2_2_2_, authgroup2_.createdBy as createdB3_2_2_, authgroup2_.isActive as isActive4_2_2_, authgroup2_.modifiedAt as modified5_2_2_, authgroup2_.updatedBy as updatedB6_2_2_, authgroup2_.version as version7_2_2_, authgroup2_.code as code8_2_2_, authgroup2_.name as name9_2_2_, owningorg3_.id as id1_18_3_, owningorg3_.createdAt as createdA2_18_3_, owningorg3_.createdBy as createdB3_18_3_, owningorg3_.isActive as isActive4_18_3_, owningorg3_.modifiedAt as modified5_18_3_, owningorg3_.updatedBy as updatedB6_18_3_, owningorg3_.version as version7_18_3_, owningorg3_.code as code8_18_3_, owningorg3_.companyId as company11_18_3_, owningorg3_.description as descript9_18_3_, owningorg3_.name as name10_18_3_, company4_.id as id1_4_4_, company4_.createdAt as createdA2_4_4_, company4_.createdBy as createdB3_4_4_, company4_.isActive as isActive4_4_4_, company4_.modifiedAt as modified5_4_4_, company4_.updatedBy as updatedB6_4_4_, company4_.version as version7_4_4_, company4_.description as descript8_4_4_, company4_.name as name9_4_4_ </p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">from List list0_ </p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">left outer join ListAuthGroup authgroups1_ on list0_.id=authgroups1_.listId </p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">left outer join AuthGroup authgroup2_ on authgroups1_.authGroupId=authgroup2_.id </p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">left outer join OwningOrg owningorg3_ on list0_.owningOrgId=owningorg3_.id </p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">left outer join Company company4_ on owningorg3_.companyId=company4_.id </p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">where ( authgroup2_.isActive = 1) and list0_.id=? and ( list0_.isActive = 1)</p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">##########</p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">I don't know if maybe I'm looking at it all wrong, but just because a child is not active should not mean a parent doesn't exist. My expectation would be one of two things, either it should be putting the active in the ON of the join, or it should be splitting this into two queries (one for the List and one for the children).</p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">I tested removing the ( authgroup2_.isActive = 1) from the WHERE and it returns results, where this returns none.</p> <p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0">Any help in either understanding that I am using this wrong, or a possible future fix would be greatly appreciated.</p> </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-11648?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-11648#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-69fe934f-ca08-45a2-8609-91b77fae0dc4" 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-11648#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-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.892.2#100040-<span title="0bee0d565732c77a6b87de662aa6d5c7adc5c354" data-commit-id="0bee0d565732c77a6b87de662aa6d5c7adc5c354}">sha1:0bee0d5</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-41a0900c-f2de-4eb0-a372-316ef4b589bf" alt="Atlassian logo" title="Atlassian logo" width="169" height="36" class="image_fix"> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
            </tbody>
        </table>   
    </body>
</html>