-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: HIbernate: Cascade during flush is dangerous
PostPosted: Wed Apr 09, 2014 6:36 am 
Newbie

Joined: Fri Apr 05, 2013 5:42 am
Posts: 2
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.