# No row with the given identifier exists error during refresh operation after an update operation

**URL:** https://discourse.hibernate.org/t/no-row-with-the-given-identifier-exists-error-during-refresh-operation-after-an-update-operation/3252
**Category:** Hibernate ORM
**Created:** [September 19, 2019, 8:41pm UTC](https://discourse.hibernate.org/t/no-row-with-the-given-identifier-exists-error-during-refresh-operation-after-an-update-operation/3252 "2019-09-19T20:41:51Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![alejo-17](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@alejo-17](https://discourse.hibernate.org/u/alejo-17)
#### Post date: [September 19, 2019, 8:41pm UTC](https://discourse.hibernate.org/t/no-row-with-the-given-identifier-exists-error-during-refresh-operation-after-an-update-operation/3252/1 "2019-09-19T20:41:51Z")

</div>

I have one A class which has a one to many relation with a list of another B objects. The summary of the process is that we are always deleting all of the rows of B before inserting new ones. The code is kind of similar of this:

@Entity  
public class A {  
private Set **b = new HashSet(0);  
 @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = “a”)  
protected Set getBList() {  
return this.b;  
}  
}**

Session session = HibernateTool.getCurrentSession();  
Criteria crit = session.createCriteria(A.class)  
.setCacheable(true);  
A existingObject = (A) crit.uniqueResult();

final Session session = HibernateTool.getCurrentSession();  
final SQLQuery query = session.createSQLQuery(“DELETE FROM B WHERE A\_ID = ?”);  
query.setLong(0, getId());  
query.executeUpdate();  
getBList.clear();  
session.save(existingObject);

```
        B b = new B();
    getBList().add(b);

```

//performs similar to saveOrUpdate  
session.update(existingObject);

//Throws exception  
session.refresh(existingObject);

Sometimes I’m getting this exception: org.hibernate.UnresolvableObjectException: No row with the given identifier exists: [B#470]

I know that issue happens when the entity does not exist in the database at the moment of the refresh, so I’m guessing the update sometimes does not consider all the properties, or I’m not doing the correct clean up before adding new ones (i.e getBList().clear() is wrong).

I saw this is a similar case [https://hibernate.atlassian.net/browse/HHH-2305](https://hibernate.atlassian.net/browse/HHH-2305)

I’m currently using hibernate core 4.2.27.Final-redhat-1

Also, I’m using second level cache for the entity A, and B, but not for the OneToMany association.

I found this as a possible workaround:

session.evict(existingObject);  
session.load(existingObject, existingObject.getId());

Your help will be appreciated.

Thanks
