batch insert using hibernate()

114 Views Asked by At

I 'm batch inserting a large array of entity into database table and this is my service but i'm getting error shown below after class:

@Override
public void parseEntitiesListFile() throws CsvValidationException, IOException, Exception {

        CSVReader csvReader = new CSVReader(new FileReader(fileDirctory));
        csvReader.skip(1);
     
      String[] values = null;
      
      while((values = csvReader.readNext()) != null) {
          FFIList fFIListObject = new FFIList(); 
          fFIListObject.setGiin(values[0]);
          fFIListObject.setFinM(values[1]);
          fFIListObject.setCountryNm(values[2]);
          fFIListEntitys.add(fFIListObject);
      }
      
      logger.info("our array size = "+ fFIListEntitys.size());
      
      final int chunkSize = 2000;
      
      List<List<FFIList>> result = Partition.ofSize(fFIListEntitys, chunkSize);
      
      logger.info("Result list size: " + result.size());
      
      Configuration config = new Configuration();
     
      config.addAnnotatedClass(FFIList.class);
      SessionFactory sessionFactory = config.buildSessionFactory();
      Session session = sessionFactory.openSession();
      Transaction transaction = session.beginTransaction();
      int counter = 1;
      for(FFIList fFIList: fFIListEntitys) {
          logger.info("saving element: " + counter);
          session.save(fFIList);
          if(counter % 30 == 0) {
              session.flush();
              session.clear();
          }
          counter++;
      }
      
      transaction.commit();
      session.close();
      sessionFactory.close();
     
}

// and this is my entity

@Entity
@Table(name ="FFIListFull3")
public class FFIList {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name ="GIIN")
private String giin;  //Global Intermediary Identification Number

@Column(name ="FINm")
private String finM;   //Financial Institution Name

@Column(name ="CountryNm")
private String countryNm;



public FFIList() {
    super();
    // TODO Auto-generated constructor stub
}

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public String getGiin() {
    return giin;
}

public void setGiin(String giin) {
    this.giin = giin;
}

public String getFinM() {
    return finM;
}

public void setFinM(String finM) {
    this.finM = finM;
}

public String getCountryNm() {
    return countryNm;
}

public void setCountryNm(String countryNm) {
    this.countryNm = countryNm;
}

@Override
public String toString() {
    return "FFIList [id=" + id + ", giin=" + giin + ", finM=" + finM + ", 
    countryNm=" + countryNm + "]";
}


}

But I'm getting this error :

Error accessing field [private java.lang.String com.datagearbi.entity.FFIList.countryNm] by reflection for persistent property [com.datagearbi.entity.FFIList#countryNm] : FFIList [id=null, giin=86YDPX.00000.LE.840, finM=Teak Hill Fund(General Partner)LLC, countryNm=UNITED STATES]`

And this error is in spring boot and hibernate 5 I used also 4 but the same error still exist

0

There are 0 best solutions below