Sueleyman Vurucu
2013-01-15 12:41:31 UTC
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 ***@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 ***@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 ***@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 ***@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]
"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 ***@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 ***@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 ***@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 ***@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]