Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects versions: 5.2.15
    • Fix versions: 5.2.17, 5.3.0.CR2
    • Components: documentation
    • Labels:
      None
    • Last commented by a user?:
      true
    • Sprint:

      Description

      http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#batch-session-batch-insert

          for ( int i = 0; i < entityCount; ++i ) {
              Person Person = new Person( String.format( "Person %d", i ) );
              entityManager.persist( Person );
      
              if ( i > 0 && i % batchSize == 0 ) {
                  //flush a batch of inserts and release memory
                  entityManager.flush();
                  entityManager.clear();
              }
          }
      

      The first batch size will be batchSize+1, I think it should be

          for ( int i = 0; i < entityCount; i++ ) {
              Person Person = new Person( String.format( "Person %d", i ) );
              entityManager.persist( Person );
      
              if ( (i + 1) % batchSize == 0 ) {
                  //flush a batch of inserts and release memory
                  entityManager.flush();
                  entityManager.clear();
              }
          }
      

      And early version http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#batch

      Session session = sessionFactory.openSession();
      Transaction tx = session.beginTransaction();
         
      for ( int i=0; i<100000; i++ ) {
          Customer customer = new Customer(.....);
          session.save(customer);
          if ( i % 20 == 0 ) { //20, same as the JDBC batch size
              //flush a batch of inserts and release memory:
              session.flush();
              session.clear();
          }
      }
         
      tx.commit();
      session.close();
      

      First batch size will be 1, mislead lots of people such as https://stackoverflow.com/questions/7349464/bulk-insert-or-update-with-hibernate

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: