<!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/0808c63f988075fb1955ccc03ecedd90?s=48&amp;d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F0808c63f988075fb1955ccc03ecedd90%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="nikowitt" id="email_nikowitt" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=nikowitt" style="color:#6c797f;; color: #3b73af; text-decoration: none">Niko Wittenbeck</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-12425" style="color: #3b73af; text-decoration: none"><img src="cid:jira-generated-image-avatar-cb242b5d-13a1-48aa-86f9-5ed48f36c02e" height="16" width="16" border="0" align="absmiddle" alt="Bug" style="vertical-align: text-bottom"></a> <a href="https://hibernate.atlassian.net/browse/HHH-12425" style="color: #3b73af; text-decoration: none">HHH-12425</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-12425" style="color: #3b73af; text-decoration: none">LazyInitializationIssue when enhancement enableDirtyTracking is enabled after session is committed</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="nikowitt" id="email_nikowitt" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=nikowitt" style="color:#6c797f;; color: #3b73af; text-decoration: none">Niko Wittenbeck</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">Hi there,<br><br>using bytecode enhancement with enableDirtyTracking=true and enabled second level cache, I'm encountering lazy init exceptions when the enhanced codes tries to clear the dirty attributes:<br><br>{noformat}<br>org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed<br><br> at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:582)<br> at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:574)<br> at org.hibernate.collection.internal.AbstractPersistentCollection.access$200(AbstractPersistentCollection.java:55)<br> at org.hibernate.collection.internal.AbstractPersistentCollection$1.doWork(AbstractPersistentCollection.java:165)<br> at org.hibernate.collection.internal.AbstractPersistentCollection$1.doWork(AbstractPersistentCollection.java:146)<br> at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:247)<br> at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:145)<br> at org.hibernate.collection.internal.PersistentSet.size(PersistentSet.java:143)<br> at com.sobis.jaf.model.security.sid.JafSid.$$_hibernate_clearDirtyCollectionNames(JafSid.java)<br> at com.sobis.jaf.model.security.sid.JafSid.$$_hibernate_clearDirtyAttributes(JafSid.java)<br> at org.hibernate.tuple.entity.PojoEntityTuplizer.afterInitialize(PojoEntityTuplizer.java:297)<br> at org.hibernate.persister.entity.AbstractEntityPersister.afterInitialize(AbstractEntityPersister.java:4659)<br> at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:284)<br> at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:128)<br> at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1152)<br> at org.hibernate.loader.Loader.processResultSet(Loader.java:1011)<br> at org.hibernate.loader.Loader.doQuery(Loader.java:949)<br> at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)<br> at org.hibernate.loader.Loader.doList(Loader.java:2692)<br> at org.hibernate.loader.Loader.doList(Loader.java:2675)<br> at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2507)<br> at org.hibernate.loader.Loader.list(Loader.java:2502)<br> at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109)<br> at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1897)<br> at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:370)<br> at com.sobis.jaf.tests.setup.DatabasePopulation.startBasicSetup(DatabasePopulation.java:122){noformat}<br><br>This error always happens after clearing the persistence context (either manually or when doing a commit) when the authority is reloaded:<br>{code:java}<br>&nbsp;&nbsp;Authority a = new Authority();<br>&nbsp;&nbsp;JafSid sid = new JafSid().setSid("sid!");<br>&nbsp;&nbsp;sid.setRelatedEntity(a);<br>&nbsp;&nbsp;sid.setClassType("type!");<br>&nbsp;&nbsp;a.setClassType("type");<br>&nbsp;&nbsp;a.setSid(sid);<br>&nbsp;&nbsp;a.setAuthority("name");<br>&nbsp;&nbsp;$session().save(a);<br>&nbsp;&nbsp;$session().flush();<br>&nbsp;&nbsp;$session().clear();<br>//throws exception in next line!<br>&nbsp;&nbsp;LOGGER.error("auth: {}", $session().get(Authority.class, a.getId()));<br>{code}<br><br>where <br>{code:java}<br>@Entity<br>public class Authority extends SidEntity&lt;BOUser&gt; {<br><br>(...)<br>}<br>{code}<br>where SidEntity is<br>{code:java}<br>@Entity<br>@Table(name = SidEntity.TABLE)<br>public abstract class SidEntity&lt;BO extends BOSidEntity&lt;? extends SidEntity&lt;BO&gt;&gt;&gt; extends Base&lt;BO&gt; {<br>(...)<br>private JafSid sid;<br>(...)<br> @OneToOne(mappedBy = JafSid.RELATED_ENTITY, optional = false, fetch = FetchType.EAGER, orphanRemoval = true)<br> @IndexedEmbedded(depth = 1, prefix = SID + JSONFieldDefinition.MODEL_SUFFIX)<br> @Cascade(CascadeType.ALL)<br> public JafSid getSid() {<br>&nbsp;&nbsp;return sid;<br> }<br>(...)<br>}<br>{code}<br>where JafSid is<br><br>{code:java}<br>public class JafSid extends Base&lt;BOJafSid&gt; implements Sid {<br>(...)<br>private Set&lt;UserGroup&gt; groups = new LinkedHashSet&lt;&gt;();<br><br>(...)<br><br>@IndexedEmbedded(depth = 1, prefix = GROUPS + JSONFieldDefinition.MODEL_SUFFIX)<br> @ManyToMany(mappedBy = UserGroup.MEMBERS)<br> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)<br> public Set&lt;UserGroup&gt; getGroups() {<br>&nbsp;&nbsp;return groups;<br> }<br>{code}<br>where Base is<br>{code:java}<br>@Entity<br>@Polymorphism(type = PolymorphismType.EXPLICIT)<br>@Inheritance(strategy = InheritanceType.JOINED)<br>@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, include = "non-lazy")<br>public abstract class Base&lt;BO extends BOBase&lt;? extends Base&lt;BO&gt;&gt;&gt; extends DatabaseEntity&lt;BO&gt; implements IBase {<br>(...)<br>}<br>{code}<br>where DatabaseEntity is<br>{code:java}<br>@MappedSuperclass<br>@BusinessLogic(relevantSecurityFields = {})<br>public abstract class DatabaseEntity&lt;BO extends BODatabaseEntity&lt;? extends DatabaseEntity&lt;BO&gt;&gt;&gt;<br>&nbsp;&nbsp;implements IDatabaseEntity, Comparable&lt;DatabaseEntity&lt;BO&gt;&gt; {<br>(...)<br>}<br>{code}<br>The issue happens in TwoPhaseLoad.doInitializeEntity, when the hydrated state of JafSid</span> <span class="diffaddedchars" style="background-color:#ddfade;">.getGroups()</span> <span class="diffcontext"> is resolved.<br><br> !image-2018-03-22-16-47-49-937.png|thumbnail! <br><br>The collection that needs to be taken from this.xrefLoadingCollectionEntries throws the LazyInitializationException.<br><br>Maybe this already gives enough clues. As the inheritance structure of the entities is quite difficult, I wasn't able to prepare an isolated test case yet, but maybe this already helps to fix the issue.</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-12425?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-12425#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-b84bedd9-2cdb-4095-b761-8765200bfd20" 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-12425#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">(v1001.0.0-SNAPSHOT#100082-<span title="91c8a36cda5b1f681cef3a0ff34233e325289529" data-commit-id="91c8a36cda5b1f681cef3a0ff34233e325289529}">sha1:91c8a36</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-dd60bd26-4672-45a8-b09c-f3f5d70e4f14" 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 src="https://u4043402.ct.sendgrid.net/wf/open?upn=YNXLe5Uzuivj8jGpuXra04BSJ-2BS7raa1puTAtyVUP-2F0UG25sB-2BHToWWBMcbXwnNUV-2B-2BXju4JhdxVHxc8suXty3EqcJFxWf7t9Xn3Aiu5wbuvugC2B3xQaQNoSzRnvMlLoeJolBo7RpyJ-2FV-2FDkPC0jB7-2FV01B0zARHijf0us3e86XUcpuv2q5dbYMjbfTw4-2FFaD0TzdDb7m-2FlnaVmWVwpZGiGR9zQYNlsjv202rXcVY-2FYMSIrl9AyShqXV7ZfFUH3aSE-2FlVV7tVE1bzhmD-2FhNXgVJlUPMfIRzN3ChON7gPxYbgqsmZNqS-2BCsdsZV-2FwTHIYtMH2-2BOfMYFgUvgKkw43wLKo7HM98Io9HWNXj1e-2FTqCAGysZeB2j7VsV40HXtOjmJUk3fNOGWUFH9gLPJkQG5EOx3zAnfkOY-2BK8gk0aRIqGP9jC5vfgN7LpwgpT7mBVn3iVlv43CFUFAR0i3HD1u6g-3D-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;"/>
</body>
</html>