Retrying after database error causes Hibernate exception

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
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

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();
		//set other fields;
	}else {

Under highly concurrent circumstances

Are you sharing a persistence context across these concurrent operations? That is usually the case when encountering this assertion error, as Hibernate’s Session (or corresponding JPA EntityManager) does not support being used across multiple threads or concurrent transactions (see e.g. the introduction guide).