<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Strange problem with Entitymanager.remove()
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/suikast42">Sueleyman Vurucu</a> in <i>EJB3</i> - <a href="https://community.jboss.org/message/791994#791994">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi guys,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have a strange problem to delete entities in bulk mode from JSF managed CDI bean. If I trigger the delete method from an EJB than it's works as excpected. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>This is my "Bulk" delete method. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java"> @Override
&#160; <font color="navy"><b>public</b></font> &lt;T <font color="navy"><b>extends</b></font> EditableIF&gt; List&lt;Long&gt; makeTransient(List&lt;T&gt; editables)<font color="navy">{</font>
&#160;&#160;&#160; <font color="navy"><b>try</b></font> <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (editables == <font color="navy"><b>null</b></font> || editables.size() == 0) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.error(<font color="red">"Nothing to delete"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> <font color="navy"><b>new</b></font> ArrayList&lt;&gt;();
&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160; <font color="darkgreen">// Backup the current flushmode</font>
&#160;&#160;&#160;&#160;&#160; FlushModeType flushModeBefore = em.getFlushMode();
&#160;&#160;&#160;&#160;&#160; em.setFlushMode(FlushModeType.COMMIT);
&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>int</b></font> i = 0;
&#160;&#160;&#160;&#160;&#160; <font color="darkgreen">// Save or update all editables and flush every 50 times</font>
&#160;&#160;&#160;&#160;&#160; ArrayList&lt;Long&gt; ids = <font color="navy"><b>new</b></font> ArrayList&lt;&gt;();
&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>for</b></font> (T eif : editables) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; em.remove(mergeIfNeeded(eif));
&#160;&#160;&#160;&#160;&#160;&#160;&#160; ids.add(eif.getId());
&#160;&#160;&#160;&#160;&#160;&#160;&#160; i++;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (i % BULK_FLUSH_SIZE == 0) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; em.flush();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160; em.flush();
&#160;&#160;&#160;&#160;&#160; em.setFlushMode(flushModeBefore);
&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> ids;
&#160;&#160;&#160; <font color="navy">}</font> <font color="navy"><b>catch</b></font> (HibernateException ex) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>throw</b></font> <font color="navy"><b>new</b></font> InfrastructureException(ex);
&#160;&#160;&#160; <font color="navy">}</font>
&#160; <font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The intent of this mehtod is that I wan't improve performance for big deletions. As I said, if I trigger this method from&#160; an EJB then it works fine. But if I trigger this from an SessionScoped CDI bean then the database entries are not deleted. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>For tracking the behaviuour of hibernate I switch the loglevel of org.hibernate.event.internal.DefaultDeleteEventListener to TRACE and add a delete interceptor. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The related logentires are shown below: </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">13:36:58,120 TRACE [org.hibernate.event.internal.DefaultDeleteEventListener] (http-localhost-127.0.0.1-8080-4) Deleting a persistent!
  instance
13:36:58,135 TRACE [org.hibernate.event.internal.DefaultDeleteEventListener] (http-localhost-127.0.0.1-8080-4) Deleting [com.siemag.components.model.message.MessagePrototype#281280]
13:36:58,135 INFO&#160; [com.siemag.components.server.updating.DomainInterceptor] (http-localhost-127.0.0.1-8080-4) Delete ID 281280 entity com.siemag.components.model.message.MessagePrototype@917079[Id=281280,name=CC011/1444,creationTime=Sun Jan 13 15:09:44 CET 2013]
13:36:58,135 TRACE [org.hibernate.event.internal.DefaultDeleteEventListener] (http-localhost-127.0.0.1-8080-4) Deleting a persistent instance
13:36:58,151 TRACE [org.hibernate.event.internal.DefaultDeleteEventListener] (http-localhost-127.0.0.1-8080-4) Deleting [com.siemag.components.model.message.MessagePrototype#281281]
13:36:58,151 INFO&#160; [com.siemag.components.server.updating.DomainInterceptor] (http-localhost-127.0.0.1-8080-4) Delete ID 281281 entity com.siemag.components.model.message.MessagePrototype@1914f6[Id=281281,name=HBS/145,creationTime=Sun Jan 13 15:09:44 CET 2013]
13:36:58,634 TRACE [org.hibernate.event.internal.DefaultDeleteEventListener] (http-localhost-127.0.0.1-8080-4) Deleting a persistent instance
13:36:58,634 TRACE [org.hibernate.event.internal.DefaultDeleteEventListener] (http-localhost-127.0.0.1-8080-4) Deleting [com.siemag.components.model.message.MessagePrototype#281280]
13:36:58,634 INFO&#160; [com.siemag.components.server.updating.DomainInterceptor] (http-localhost-127.0.0.1-8080-4) Delete ID 281280 entity com.siemag.components.model.message.MessagePrototype@adfa17[Id=281280,name=CC011/1444,creationTime=Sun Jan 13 15:09:44 CET 2013]
13:36:58,650 TRACE [org.hibernate.event.internal.DefaultDeleteEventListener] (http-localhost-127.0.0.1-8080-4) Deleting a persistent instance
13:36:58,650 TRACE [org.hibernate.event.internal.DefaultDeleteEventListener] (http-localhost-127.0.0.1-8080-4) Deleting [com.siemag.components.model.message.MessagePrototype#281281]
13:36:58,650 INFO&#160; [com.siemag.components.server.updating.DomainInterceptor] (http-localhost-127.0.0.1-8080-4) Delete ID 281281 entity com.siemag.components.model.message.MessagePrototype@1616c73[Id=281281,name=HBS/145,creationTime=Sun Jan 13 15:09:44 CET 2013]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The strange thing here is that hibernate recognize the delete action but it doesn't excecute a delete statement on the DB. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thanks in advance. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>My runtime:</p><p>Jboss 7.1.1.Final</p><p>Hibernate 4.1.4.Final</p><p>Primefaces 3.4.2</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/791994#791994">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB3 at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>