<!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/df12d7792bd3b7be3a4edf12cabd58cb?s=48&amp;d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fdf12d7792bd3b7be3a4edf12cabd58cb%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="steve" style="color:#6c797f;; color: #3b73af; text-decoration: none" id="email_steve" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3Aaafa2e9a-7a21-4c62-bf4a-050acb31276c"> Steve Ebersole </a> <strong>commented</strong> on <a href="https://hibernate.atlassian.net/browse/HHH-11147?atlOrigin=eyJpIjoiYTFlMTY5ZGUwOTY1NDBkZTk0YzdhODkzOGFjMzE2MTUiLCJwIjoiaiJ9" style="color: #3b73af; text-decoration: none"><img src="cid:jira-generated-image-avatar-22e7a62f-6516-4543-9fec-0d3078e49824" height="16" width="16" border="0" align="absmiddle" alt="New Feature"> HHH-11147</a> </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 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-11147?atlOrigin=eyJpIjoiYTFlMTY5ZGUwOTY1NDBkZTk0YzdhODkzOGFjMzE2MTUiLCJwIjoiaiJ9" style="color: #3b73af; text-decoration: none">Re: Allow enhanced entities to be returned in a completely uninitialized state</a> </span> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td id="text-paragraph-pattern-top" class="email-content-main mobile-expand  comment-top-pattern" 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; border-bottom: none; padding-bottom: 0" 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: 10px 0 0; margin-top: 0"><a href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058:57b78197-578e-4af9-9e41-2519cf70478f" class="user-hover" rel="andreaboriero" data-account-id="557058:57b78197-578e-4af9-9e41-2519cf70478f" accountid="557058:57b78197-578e-4af9-9e41-2519cf70478f" style="color: #3b73af; text-decoration: none">Andrea Boriero</a> and I have been working on this and I think it is pretty close.</p> <p style="margin: 10px 0 0">I wanted to outline the approach being taken to get feedback. PR forthcoming soon too...</p> <p style="margin: 10px 0 0">First a few terms so we can have a common "language" in discussing this. For lack of a better name we called this a "bytecode proxy" or "enhancement proxy". We already have the notion of "fetch groups", including the "default fetch group"; this work adds a new conceptual "base fetch group" (think all of the state that was previously "loaded" when the enhanced entity is created.</p> <p style="margin: 10px 0 0">The first step was to "clean up" <tt>org.hibernate.mapping.Property#isLazy</tt>, <tt>org.hibernate.persister.entity.EntityPersister#hasProxy</tt> and a few other questionable named/used methods. The javadocs I added to <tt>Property#isLazy</tt> explains a lot of this:</p> 
                                                        <div class="code panel" style="border-width: 1px;; border: 1px solid #cccccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #cccccc; -moz-border-radius: 3px; border-radius: 3px; margin: 9px 0">
                                                            <div class="codeContent panelContent" style="padding: 9px 12px"> 
                                                                <pre class="code-java" style="margin: 10px 0 0; margin-top: 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal">

        /**
         * Is <span class="code-keyword" style="color: #000091">this</span> property lazy in the <span class="code-quote" style="color: #009100">"bytecode"</span> sense?
         *
         * Lazy here means whether we should push *something* to the entity
         * instance <span class="code-keyword" style="color: #000091">for</span> <span class="code-keyword" style="color: #000091">this</span> field in its <span class="code-quote" style="color: #009100">"base fetch group"</span>.  Mainly it affects
         * whether we should list <span class="code-keyword" style="color: #000091">this</span> property's columns in the SQL select
         * <span class="code-keyword" style="color: #000091">for</span> the owning entity when we load its <span class="code-quote" style="color: #009100">"base fetch group"</span>.
         *
         * The <span class="code-quote" style="color: #009100">"something"</span> we push varies based on the nature (basic, etc) of
         * the property.
         */
        <span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">boolean</span> isLazy() {
                <span class="code-keyword" style="color: #000091">if</span> ( value <span class="code-keyword" style="color: #000091">instanceof</span> ToOne ) {
                        <span class="code-comment" style="color: #808080">// For a many-to-one, <span class="code-keyword" style="color: #000091; color: #808080">this</span> is always <span class="code-keyword" style="color: #000091; color: #808080">false</span>.  Whether the
</span>                        <span class="code-comment" style="color: #808080">// association is EAGER, PROXY or NO-PROXY we want the fk
</span>                        <span class="code-comment" style="color: #808080">// selected
</span>                        <span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">false</span>;
                }

                <span class="code-keyword" style="color: #000091">return</span> lazy;
        }
</pre> 
                                                            </div>
                                                        </div> <p style="margin: 10px 0 0">The important take away is the impact on the SQL select for the base fetch group. As noted in other comments - previously if enhancement is used and <tt>NO_PROXY</tt> is specified for a to-one, the columns making up the FK are not rendered in the SQL select for the base fetch group. This change effectively changes that behavior to always select the FKs for all to-ones (just the FK value). </p> <p style="margin: 10px 0 0">So when we go to hydrate/resolve the to-one property from a ResultSet, its FK value is always available in the result set. In the <tt>NO_PROXY</tt> case, this then leads us to...</p> <p style="margin: 10px 0 0"><tt>org.hibernate.event.internal.DefaultLoadEventListener#proxyOrLoad</tt> was also changed to understand and account for this. The main change here is the addition of a new <tt>org.hibernate.engine.spi.PersistentAttributeInterceptor</tt> implementation I named <tt>EnhancementAsProxyLazinessInterceptor</tt> (better name forthcoming). Back in <tt>#proxyOrLoad</tt>, in this "bytecode proxy" case, we:</p> 
                                                        <ol> 
                                                            <li>instantiate the enhanced entity,</li> 
                                                            <li>set its identifier,</li> 
                                                            <li>create a EnhancementAsProxyLazinessInterceptor,</li> 
                                                            <li>push the interceptor to the entity</li> 
                                                        </ol> <p style="margin: 10px 0 0">The interceptor triggers loading of the entity's base fetch group at which time it also injects the "normal" interceptor to the entity.</p> <p style="margin: 10px 0 0">All in all this works very well. But there are downsides and it changes certain little behaviors, hence I am adding a setting to enable/disable this (disabled by default I am thinking for compatibility). The downsides mainly center on <tt>org.hibernate.Hibernate</tt> and its methods returning different answers. Specifically:</p> 
                                                        <ol> 
                                                            <li><tt>#isInitialized</tt> - I added a block to deal with these bytecode proxies. That itself is not so bad I guess since this is something new.</li> 
                                                            <li><tt>#isPropertyInitialized</tt> - this is the bigger one. The contract for this method, when passed an enhanced entity, is to return whether that property is set on the instances field (back to the "bytecode lazy" comments above). Well with this new bytecode proxy feature all the to-one associations <b>are</b> initialized (once the base fetch group is loaded). For example, this leads to lots of test failures which assume a call to <tt>Hibernate.isPropertyInitialized( entity, "theToOne" )</tt> returning true means the <tt>MyToOne</tt> entity itself is initialized. We could approximately the older behavior by having <tt>#isPropertyInitialized</tt> additionally check the initialized state of the associated entity if it is enhanced as well. Kind of torn about this. I think both pieces of information have value separately. I could be persuaded that this approximation is ok though. The other "solution" would be change the test code (and apps relying on this behavior as well) to check both or allow a setting to opt out of bytecode-proxy support.</li> 
                                                        </ol> <p style="margin: 10px 0 0">I think we may also want to alter <tt>Hibernate#initialize</tt> to account for bytecode enhancement. ATM it does not, like at all. It only has any effect when the thing based in is an uninitialized traditional proxy or an uninitialized collection. For an uninitialized enhanced entity it does nothing. The question there becomes what exactly should happen. Does this trigger just the base fetch group? All fetch groups? Not sure there is a "correct" answer here.</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-11147?inbox=true&focusedCommentId=105051&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-105051",
    "name": "View Comment"
      },
  "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-11147#add-comment?atlOrigin=eyJpIjoiYTFlMTY5ZGUwOTY1NDBkZTk0YzdhODkzOGFjMzE2MTUiLCJwIjoiaiJ9" 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-8051d88b-1135-4da3-a320-078c0039eda0" 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-11147#add-comment?atlOrigin=eyJpIjoiYTFlMTY5ZGUwOTY1NDBkZTk0YzdhODkzOGFjMzE2MTUiLCJwIjoiaiJ9" 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&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&ct=EmailNotificationLink&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">(v1001.0.0-SNAPSHOT#100099-<span title="adbe2fa4c5c17f9c5e95a9541b61463e837087d9" data-commit-id="adbe2fa4c5c17f9c5e95a9541b61463e837087d9}">sha1:adbe2fa</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; opacity: 0.150"> <img id="footer-pattern-logo-desktop" src="cid:jira-generated-image-static-footer-desktop-logo-37410e93-5a49-47bf-85c3-0e3661d889e8" 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>   
    
<img border="0" width="1" height="1" alt="" src="http://atlassian.et.e.sparkpost.com/q/uOG0kh4WaNh4ZjfI84vWBQ~~/AAAAAQA~/RgRemwmgPlcLYXRsYXNzaWFudXNCCgAAINa5XI0dRaxSIGhpYmVybmF0ZS1pc3N1ZXNAbGlzdHMuamJvc3Mub3JnWAQAAAAE">
</body>
</html>