Hi
I am having a Batch process which processes a file and inserts records from the file into database. I have two environments dev and production. This process always works fine in Dev but sometime fails in prodcution environment throwing the below error:
"Error in inserting data in table:::org.hibernate.HibernateException: Flush during cascade is dangerous."
I am not able to undertand where this logic is failing and that too sometimes.
My code is:
int count =0; try { foreTime = Functions.getDate(record.getDateTime(),"dd/MM/yyyy HH:mm"); targetDateTime = Functions.getDate(record.getTargetDateTime(),"dd/MM/yyyy HH:mm"); logger.debug("targetDateTime:" + targetDateTime); } catch (Exception e) { logger.error("Error while validating date");
} if (errorFlag == false) { logger.info("inserting into database"); try {
foreData = new ForeData(); compoundKey = new ForeDataCompoundKey(); compoundKey.setForeTime(Functions.getDate(record.getForeTime(),"dd/MM/yyyy HH:mm")); compoundKey.setForeId(foreId); foreData .setKey(compoundKey); foreData .setForecastWd0(Record.getWindDirection0()); foreData .setForecastWs0(Record.getWindSpeed0()); updateData(foreData,fileName, session); if (++count % 1000 == 0) { session.flush(); } output.info("updating the database"); // tx.commit(); } catch (HibernateException e) {
errorMessage = sqlEx.getMessage(); errorCode = sqlEx.getErrorCode(); message = "Error in inserting data in table"; throw new QueryException("Exception occured"); }
and updateData(foreDtaa, filename , session) method is like:
updateData(ForeData foreData, String fileName, Session session) { try { IHibernateDAO<ForeData, ForeDataCompoundKey> dao = (IHibernateDAO<ForeData, ForecDataCompoundKey>) SpringUtil .lookup("HibernateDAOBean"); dao.setPersistentClass(ForeData.class); dao.setSession(session); dao.saveNoFlush(foreData);
} catch (Exception ex) {
}
and saveNoFlush() method is:
public T saveNoFlush(T entity) throws QueryException { try { // Transaction tx = session.beginTransaction(); getSession().save(entity); // tx.commit(); return entity; } catch (Exception e) {
}
Can you please look into it and tell me why this error is coming up and that too intermittently?
Thanks.
|