Under highly concurrent circumstances, the application trigger unique constraints while saving new data. So we have retry mechanism to fetch the data from DB again and if the data already present we will not save again.
But in the retry logic while trying to fetch data from postgresDB we are getting the following error:
ERROR :HHH000099: an assertion failure occurred (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: null id in io.cred.rj.demo.entity.Merchant entry (don’t flush the Session after an exception occurs)
Retry was working initially but now always getting assertion failure error
I’ve tried catching the particular exception also rollback if DataIntegrity violation occurred. But after the uniqueconstraint exception everytime DB fetching is resulting in AssertionFailure error from hibernate.
Example code:
public void cleanseMerchant(Merchant description, String mcc) {
try {
updateOrAddMerchant(description,mcc );
}catch(Exception e) {
//Retrying again
updateOrAddMerchant(description,mcc );
}
}
public void updateOrAddMerchant(Merchant description, String mcc) {
Merchant merchant=merchantDao.findByDescAndMcc(description,mcc);
if(merchant == null) {
Merchant merchant = new Merchant();
merchant.setMerchantDesc(description);
//set other fields
merchantDao.save(merchant);
}else {
updateMerchantInfo();
}
}
Vyshna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.