1 Reply Latest reply on Nov 25, 2011 11:38 AM by alanmehio2

    http request thread persist while different thread does not same entity manager

    alanmehio2
      We have a web page which admin and allow to persist the entity bean into the database. We are using a Jboss TreeCache for secondary cache level.
      When we try to persist the entity ( same entity) via another thread ( not the http request thread); it does not get persisted into the database even-though we are using the same entity-Manager.

      The way we try to persist is via running a command executor from the web which create a separate thread.

      The isolation level of the tree cache is READ_COMMITTED.

      If I configure another entity manager via components.xml and try to persist the entity via direct sql native update we get the below exception
      org.hibernate.cache.CacheException: org.jboss.cache.lock.TimeoutException: failure acquiring lock:
      ..
         at org.hibernate.cache.TreeCache.read(TreeCache.java:57)
            at org.hibernate.cache.TransactionalCache.put(TransactionalCache.java:45)
            at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:156)
            at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
            at org.hibernate.loader.Loader.doQuery(Loader.java:729)
            at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
            at org.hibernate.loader.Loader.doList(Loader.java:2220)
            at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2136)
            at org.hibernate.loader.Loader.list(Loader.java:2096)


      The quesiton is why when we directly from the seam view we go through the seam backbean and persist the entity it works fine ( database persisted) while if we  go through a separate thread i.e backbean is being executed under a non http thread ( request thread) the process does not get persisted into the database but rather stays in the second level cache.

      Please do ask for more details.


        • 1. Re: http request thread persist while different thread does not same entity manager
          alanmehio2
          The Asynchronous process ( new thread created) which is not on the http request thread was market as  @TransactionAttribute(TransactionAttributeThype.NOT_SUPPORTED) which made any change to update the TreeCache only and not the database upon calling EntityManger.persist(EntityBean) followed by EntityManager flus()

          By annotating it with TransactoionSupportType.SUPPORTS sort the problem and persist into the database.

          The only difference between the admin page and this process was the transaction support.