title: Reduce time while uploading data from file to mysql using hibernate
body: <p>I have a csv file which has approximately 1 million records. each row representing a student object.</p>
  
  <p>In service layer, I'm reading the csv file and changing it in to entity as below:</p>
  
  <pre><code> File file = new File("test.csv");
      try
      {
          String csvFile = "test.csv";
          BufferedReader br = null;
          String line = "";
          String cvsSplitBy = ",";
          try
          {
              br = new BufferedReader(new FileReader(csvFile));
              while ((line = br.readLine()) != null)
              {
                  // use comma as separator
                  String[] student = line.split(cvsSplitBy);
                  System.out
                      .println("Country [code= " + student[0] + " , name=" + student[1] + "]");
                  StudentTable st = new StudentTable();
                  st.setEmplyoee(student[0]);
                  st.setName(student[1]);
                  springbootDao.saveStudent(st);
              }
          }
          catch (FileNotFoundException e)
          {
              e.printStackTrace();
          }
          catch (IOException e)
          {
              e.printStackTrace();
          }
          finally
          {
              if (br != null)
              {
                  try
                  {
                      br.close();
                  }
                  catch (IOException e)
                  {
                      e.printStackTrace();
                  }
              }
          }
      }
      catch (Exception e)
      {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>for dao layer</p>
  
  <pre><code>void saveStudent(StudentTable st)
      {
          getSession();
          session.save(st);
          session.beginTransaction().commit();
      }
  
  
  private Session getSession()
      {
          if (session == null)
          {
              session = entity.unwrap(SessionFactory.class).openSession();
          }
          return session;
      }
  </code></pre>
  
  <p>When I am trying to save it, it is saving for 1 million time, say save for each row which should be as per the logic.</p>
  
  <p>Clearly that is not a good way. Is there anyway I can optimise it using multiple threads to enhance the speed as clearly single thread will take more time or any method in hibernate I can use to dump the data for faster speed?</p>
  
  <p>more update :</p>
  
  <p>i changed it to </p>
  
  <pre><code>while ((line = br.readLine()) != null)
  {
  // use comma as separator
  String[] student = line.split(cvsSplitBy); //java.lang.OutOfMemoryError: Java heap space
  StudentTable st = new StudentTable();
  st.setEmplyoee(student[0]);
  st.setName(student[1]);
  stList.add(st);
  }
  springbootDao.saveStudent(stList);
  </code></pre>
  
  <p>now i am facing outofmemoryerror</p>