for (int i = 1; i <= 100000; i++) {
   String ids = UUIDUtil.generateUUID();
   Customer customer = new Customer();

   EntityPk entityPk = getEntityPk(ids);
   customer.setPosition("科研人员");
   customer.setPhoneNumber("0571-888" + Math.round(Math.random()*(30001-10000)+10000));
   customer.setMale(new Integer(1));
   ....
    customerService.saveCustomer(customer);
   if (i % 200 == 0) {
    sessionFactory.getCurrentSession().flush();
    sessionFactory.getCurrentSession().clear();
    System.out.println(i+" run compeleted!!!");
   }

  
  }
 批量插入大量数据时候,需要对 Session进行及时清理,否则内存溢出.



------君临天下,舍我其谁------