[jboss-user] [EJB3] - Strange problem with Entitymanager.remove()

Sueleyman Vurucu do-not-reply at jboss.com
Tue Jan 15 07:41:31 EST 2013


Sueleyman Vurucu [https://community.jboss.org/people/suikast42] created the discussion

"Strange problem with Entitymanager.remove()"

To view the discussion, visit: https://community.jboss.org/message/791994#791994

--------------------------------------------------------------
Hi guys,

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. 


This is my "Bulk" delete method. 

 @Override
  public <T extends EditableIF> List<Long> makeTransient(List<T> editables){
    try {
      if (editables == null || editables.size() == 0) {
        log.error("Nothing to delete");
        return new ArrayList<>();
      }
      // Backup the current flushmode
      FlushModeType flushModeBefore = em.getFlushMode();
      em.setFlushMode(FlushModeType.COMMIT);
      int i = 0;
      // Save or update all editables and flush every 50 times
      ArrayList<Long> ids = new ArrayList<>();
      for (T eif : editables) {
        em.remove(mergeIfNeeded(eif));
        ids.add(eif.getId());
        i++;
        if (i % BULK_FLUSH_SIZE == 0) {
          em.flush();
        }
      }
      em.flush();
      em.setFlushMode(flushModeBefore);
      return ids;
    } catch (HibernateException ex) {
      throw new InfrastructureException(ex);
    }
  }


The intent of this mehtod is that I wan't improve performance for big deletions. As I said, if I trigger this method from  an EJB then it works fine. But if I trigger this from an SessionScoped CDI bean then the database entries are not deleted. 

For tracking the behaviuour of hibernate I switch the loglevel of org.hibernate.event.internal.DefaultDeleteEventListener to TRACE and add a delete interceptor. 

The related logentires are shown below: 


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  [com.siemag.components.server.updating.DomainInterceptor] (http-localhost-127.0.0.1-8080-4) Delete ID 281280 entity com.siemag.components.model.message.MessagePrototype at 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  [com.siemag.components.server.updating.DomainInterceptor] (http-localhost-127.0.0.1-8080-4) Delete ID 281281 entity com.siemag.components.model.message.MessagePrototype at 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  [com.siemag.components.server.updating.DomainInterceptor] (http-localhost-127.0.0.1-8080-4) Delete ID 281280 entity com.siemag.components.model.message.MessagePrototype at 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  [com.siemag.components.server.updating.DomainInterceptor] (http-localhost-127.0.0.1-8080-4) Delete ID 281281 entity com.siemag.components.model.message.MessagePrototype at 1616c73[Id=281281,name=HBS/145,creationTime=Sun Jan 13 15:09:44 CET 2013]


The strange thing here is that hibernate recognize the delete action but it doesn't excecute a delete statement on the DB. 

Thanks in advance. 

My runtime:
Jboss 7.1.1.Final
Hibernate 4.1.4.Final
Primefaces 3.4.2
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/791994#791994]

Start a new discussion in EJB3 at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130115/9b4fd435/attachment-0001.html 


More information about the jboss-user mailing list