2 Replies Latest reply on Sep 18, 2008 5:01 PM by Rene Felgenträger

    Manual Flush outside of a conversation does not work

    Rene Felgenträger Newbie

      Hi folks,

      my application needs to read a very big csv-file on the server each night (i use quartz for this job) and store the read information in the database. After round about 10 000 created objects, i get an out of memory exception. This pretty obviously, as all the created objects are hold in cache.

      I tried to fix this problem by forcing a flush manually in my loop. I tried several things, but none of them worked.

      1) SFSB with PersistenceContext and Bean-managed Transactionmanagement
      2) Seam-Pojo with SMPC and Transaction managed via @Transaction
      3) direct use of Hibernate session in a SFSB und Seam-Pojo (the transaction handling just differs as pointed in 1) and 2)) as explained according to the hibernate reference HibernateRef

      I already have exprerience with FlushMode.Manual in a conversation, this works fine. But for this task, i cannot use a conversation, as this happens only on the server side without any involvements of a request/frontend.

      Help is very much appreciated! Thanks in advance!


        • 1. Re: Manual Flush outside of a conversation does not work
          Cory Dahlstrom Novice

          Manual flush should have no affect in this situation.  Flushing the entity manager only triggers pending CRUD operations to be executed against the database.  The newly created entities still exist in the entity manager.

          In your situation you need to flush then clear the entity manager.  Clearing the entity manager will fix the out of memory issue.


          • 2. Re: Manual Flush outside of a conversation does not work
            Rene Felgenträger Newbie

            yep, clearing cache via em.clear() is the solution for the memory lack.

            But another disadvantage occured.
            I have to refresh (reload!) some (actually a bunch of) entities after the clearing, as I need to wire them with my fresh created entity from the csv-file. The reload is
            necessary otherwise i get a not attatched entity passed to persist - Exception. First, i thought it would be possible to use merge for the detached entities after invoking this.em.clear(), but this raised another error: row was updated by another transaction (i think the optimistic lock exception is it).

            Anyway, my result form bluk insert is: always use flush/clear and reload your entities. U should not care about massive database queries, as most of such work will be done at night ;)