2 Replies Latest reply on Jul 12, 2010 7:38 PM by shane lee


    Fabin Riako Newbie

      Hi All,

      I have a parent and child object, child stores parent object's id also. I have an excel file that contais data for both parent and child. I am trying to insert these values to database. If I use FlushModeType.MANUAL,

      for loop (Reading data from excel)

      First Save Parent

      ?? Do i need to call flush Here to get Parent ID (Uses sequence to generate ID)

      Set Parent.id to Child.parent

      Then Save Child

      ?? OR call flush Here


      OR call flush Here

      OR Dont use FlushModeType.MANUAL ? Please suggest

      Please help I am confused I tried everything but the application is running very slowly

      I know this is a stupid question but I am confused.


        • 1. Re: FlushModeType
          Herberson Silva Newbie

          In cases like yours I call flush after the loop, like this:

          for (read Parent from excel)
              for (read Child from Excel)

          • 2. Re: FlushModeType
            shane lee Newbie

            This scenario depends on how your transactions are managed and whether or not your your persistence context is scoped to conversation.

            Seam reference documentation states:
            By default, the persistence context is flushed (synchronized with the database) at the end of each transaction.
                This is sometimes the desired behavior. But very often, we would prefer that all changes are held in memory and
                only written to the database when the conversation ends successfully. This allows for truly atomic conversations.

            If i understand this correctly its 1:N relationship

            //First persist parent
            //Set parent id on child
            //Persist the child
            //At the end of conversation then flush your changes

            Take a look at:
            Seam-managed persistence contexts and atomic conversations

            Also read hibernate entity manager reference documentation