<style>
/* Changing the layout to use less space for mobiles */
@media screen and (max-device-width: 480px), screen and (-webkit-min-device-pixel-ratio: 2) {
    #email-body { min-width: 30em !important; }
    #email-page { padding: 8px !important; }
    #email-banner { padding: 8px 8px 0 8px !important; }
    #email-avatar { margin: 1px 8px 8px 0 !important; padding: 0 !important; }
    #email-fields { padding: 0 8px 8px 8px !important; }
    #email-gutter { width: 0 !important; }
}
</style>
<div id="email-body">
<table id="email-wrap" align="center" border="0" cellpadding="0" cellspacing="0" style="background-color:#f0f0f0;color:#000000;width:100%;">
    <tr valign="top">
        <td id="email-page" style="padding:16px !important;">
            <table align="center" border="0" cellpadding="0" cellspacing="0" style="background-color:#ffffff;border:1px solid #bbbbbb;color:#000000;width:100%;">
                <tr valign="top">
                    <td bgcolor="#3e4c4e" style="background-color:#3e4c4e;color:#ffffff;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;line-height:1;"><img src="https://www.jboss.org/dms/hibernate/images/jira/jiraheader_hibernate.png" alt="" style="vertical-align:top;" /></td>
                </tr><tr valign="top">
    <td id="email-banner" style="padding:32px 32px 0 32px;">
        
                
        
        
            <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="width:100%;">
    <tr valign="top">
        <td style="color:#505050;font-family:Arial,FreeSans,Helvetica,sans-serif;padding:0;">
                                        <img id="email-avatar" src="https://hibernate.onjira.com/secure/useravatar?ownerId=gsmet&avatarId=10640" alt="" height="48" width="48" border="0" align="left" style="padding:0;margin: 0 16px 16px 0;" />
                        <div id="email-action" style="padding: 0 0 8px 0;font-size:12px;line-height:18px;">
                                    <a class="user-hover" rel="gsmet" id="email_gsmet" href="https://hibernate.onjira.com/secure/ViewProfile.jspa?name=gsmet" style="color:#6c797f;">Guillaume Smet</a>
     created <img src="https://hibernate.onjira.com/images/icons/bug.gif" height="16" width="16" border="0" align="absmiddle" alt="Bug"> <a style='color:#6c797f;text-decoration:none;' href='https://hibernate.onjira.com/browse/HHH-7821'>HHH-7821</a>
            </div>
                        <div id="email-summary" style="font-size:16px;line-height:20px;padding:2px 0 16px 0;">
                <a style='color:#6c797f;text-decoration:none;' href='https://hibernate.onjira.com/browse/HHH-7821'><strong>2 different NPEs after upgrade from 4.1.6 to 4.1.8</strong></a>
            </div>
                    </td>
    </tr>
</table>
    </td>
</tr>
<tr valign="top">
    <td id="email-fields" style="padding:0 32px 32px 32px;">
        <table border="0" cellpadding="0" cellspacing="0" style="padding:0;text-align:left;width:100%;" width="100%">
            <tr valign="top">
                <td id="email-gutter" style="width:64px;white-space:nowrap;"></td>
                <td>
                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Issue Type:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
                <img src="https://hibernate.onjira.com/images/icons/bug.gif" height="16" width="16" border="0" align="absmiddle" alt="Bug">        Bug
    </td>
</tr>                        <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Affects Versions:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
                    4.1.8            </td>
</tr>
                        <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Assignee:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
                    Unassigned            </td>
</tr>                                                <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Components:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
                    core            </td>
</tr>
                        <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Created:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
        22/Nov/12 9:38 AM
    </td>
</tr>                        <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Description:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
        <p style='margin-top:0;margin-bottom:10px;'>From my post on the mailing list:</p>

<p style='margin-top:0;margin-bottom:10px;'>Hi,</p>

<p style='margin-top:0;margin-bottom:10px;'>After upgrading from <b>4.1.6</b> to <b>4.1.8</b>, we have a couple of regressions<br/>
in one of our applications.</p>

<p style='margin-top:0;margin-bottom:10px;'>We tried to obtain self contained test cases and understand what the<br/>
problem is but it's quite hard to reproduce and we haven't found a way<br/>
to isolate the problem yet.</p>

<p style='margin-top:0;margin-bottom:10px;'>Anyway, I was wondering if the stacktraces could ring a bell for<br/>
someone to help us analyze the problem. It might even be an obvious<br/>
bug for you once you have the stracktrace.</p>

<p style='margin-top:0;margin-bottom:10px;'>Here are both stacktraces for the regressions we have:</p>

<p style='margin-top:0;margin-bottom:10px;'>Stacktrace 1 (only when we configure the batch loading - might be due<br/>
to a race condition because it's not systematic):</p>

<p style='margin-top:0;margin-bottom:10px;'>Caused by: java.lang.NullPointerException<br/>
        at<br/>
org.hibernate.type.descriptor.java.AbstractTypeDescriptor.extractHashCode(AbstractTypeDescriptor.java:88)<br/>
        at<br/>
org.hibernate.type.AbstractStandardBasicType.getHashCode(AbstractStandardBasicType.java:210)<br/>
        at<br/>
org.hibernate.type.AbstractStandardBasicType.getHashCode(AbstractStandardBasicType.java:214)<br/>
        at org.hibernate.cache.spi.CacheKey.calculateHashCode(CacheKey.java:71)<br/>
        at org.hibernate.cache.spi.CacheKey.&lt;init&gt;(CacheKey.java:67)<br/>
        at<br/>
org.hibernate.internal.AbstractSessionImpl.generateCacheKey(AbstractSessionImpl.java:252)<br/>
        at<br/>
org.hibernate.engine.spi.BatchFetchQueue.isCached(BatchFetchQueue.java:330)<br/>
        at<br/>
org.hibernate.engine.spi.BatchFetchQueue.getCollectionBatch(BatchFetchQueue.java:312)<br/>
        at<br/>
org.hibernate.loader.collection.BatchingCollectionInitializer.initialize(BatchingCollectionInitializer.java:72)<br/>
        at<br/>
org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:678)<br/>
        at<br/>
org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:80)<br/>
        at<br/>
org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1804)<br/>
        at<br/>
org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:549)<br/>
        at<br/>
org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:234)<br/>
        at<br/>
org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:545)<br/>
        at<br/>
org.hibernate.collection.internal.PersistentBag.removeAll(PersistentBag.java:345)</p>





<p style='margin-top:0;margin-bottom:10px;'>Stacktrace 2 (we have this one even if we disable the batch loading):</p>

<p style='margin-top:0;margin-bottom:10px;'>Caused by: java.lang.NullPointerException<br/>
        at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:259)<br/>
        at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:165)<br/>
        at<br/>
org.hibernate.event.internal.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:160)<br/>
        at<br/>
org.hibernate.event.internal.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:151)<br/>
        at<br/>
org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:88)<br/>
        at<br/>
org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)<br/>
        at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1213)<br/>
        at<br/>
org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:986)<br/>
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br/>
        at<br/>
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br/>
        at<br/>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br/>
        at java.lang.reflect.Method.invoke(Method.java:597)<br/>
        at<br/>
org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)<br/>
        at $Proxy115.flush(Unknown Source)</p>


<p style='margin-top:0;margin-bottom:10px;'>Followup of this post:<br/>
The errors are quite hard to reproduce and we only have them in a <b>big</b> application with a lot of entities when we are bulk loading a lot of objects. We don't reproduce these problems on the smaller ones. That's why a self contained test case is hard to get.</p>

<p style='margin-top:0;margin-bottom:10px;'>They are totally reproducable on this application though.</p>

<p style='margin-top:0;margin-bottom:10px;'>From what we saw in the code, at least one of the stacktraces comes from a place modified in 4.1.8. That's why we hoped it could ring a bell just to have the stacktraces.</p>

<p style='margin-top:0;margin-bottom:10px;'>Typically this one:<br/>
Caused by: java.lang.NullPointerException<br/>
    at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:259)<br/>
    at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:165)<br/>
    at org.hibernate.event.internal.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:160)<br/>
    at org.hibernate.event.internal.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:151)<br/>
    at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:88)<br/>
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)<br/>
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1213)<br/>
    at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:986) </p>

<p style='margin-top:0;margin-bottom:10px;'>seems to be related to this particular commit:<br/>
<a href="https://github.com/hibernate/hibernate-orm/commit/deaff9705e564b33b92b3eac9fdee89815ce1a44">https://github.com/hibernate/hibernate-orm/commit/deaff9705e564b33b92b3eac9fdee89815ce1a44</a></p>

<p style='margin-top:0;margin-bottom:10px;'>Should we try to reproduce it in a debug environment with a conditional breakpoint to see if we can have more information about the context?</p>

<p style='margin-top:0;margin-bottom:10px;'>For the other one, I don't have any idea yet.</p>

<p style='margin-top:0;margin-bottom:10px;'>In this commit, I find a little weird that the hashCode is tested before testing the type but I don't think it might be related to the problem at hand.<br/>
<a href="https://github.com/hibernate/hibernate-orm/commit/fae0d3f49877a5a11a7ac5cef25bb91235906fab">https://github.com/hibernate/hibernate-orm/commit/fae0d3f49877a5a11a7ac5cef25bb91235906fab</a></p>
    </td>
</tr>
                                                <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Environment:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
        Hibernate 4.1.8, PostgreSQL 9.1
    </td>
</tr>
                                                <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Project:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
        <a style="color:#6c797f;" href="https://hibernate.onjira.com/browse/HHH">Hibernate ORM</a>
    </td>
</tr>                                                <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Priority:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
                <img src="https://hibernate.onjira.com/images/icons/priority_major.gif" height="16" width="16" border="0" align="absmiddle" alt="Major">        Major
    </td>
</tr>                        <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Reporter:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
                                        <a class="user-hover" rel="gsmet" id="email_gsmet" href="https://hibernate.onjira.com/secure/ViewProfile.jspa?name=gsmet" style="color:#6c797f;">Guillaume Smet</a>
                </td>
</tr>                                                    
    
    
                        </table>
                </td>
            </tr>
        </table>
    </td>
</tr>













            </table>
        </td><!-- End #email-page -->
    </tr>
    <tr valign="top">
        <td style="color:#505050;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:10px;line-height:14px;padding: 0 16px 16px 16px;text-align:center;">
            This message is automatically generated by JIRA.<br />
            If you think it was sent incorrectly, please contact your JIRA administrators<br />
            For more information on JIRA, see: <a style='color:#6c797f;' href='http://www.atlassian.com/software/jira'>http://www.atlassian.com/software/jira</a>
        </td>
    </tr>
</table><!-- End #email-wrap -->
</div><!-- End #email-body -->