dataprovider refreshitem not working correctly

I have an Entity which has this method for the hashcode and equals:

    @Override
    public int hashCode() {
        if (getId() != null) {
            return getId().hashCode();
        }
        return super.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if(!(obj instanceof AbstractEntity)) {
            return false;
        }
        AbstractEntity other = (AbstractEntity) obj;
        if(other.getVersion() != getVersion()) {
            return false;
        }
        return super.equals(obj);
    }

thats why dataprovider.refreshItem(myItem) does nothing because the hashcode is the same as before. I dont know if it breaks if i add the version to the hashcode generation.

So to be safe i want to force the dataprovider to reload that item (new item has newer version and other details). Is there a way to override the refreshitem function and force it to reload it in the view?

Okay, changing the hashcode didn’t work, it doesn’t refresh at all

Okay now it updates the view if i pass the old entity version to the method to refresh.

But it still doesnt update the item correct. Because if i try to edit the item i get an Error:
Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) :

If i use refreshAll it works fine

dataprovider refreshitem not working correctly

refreshItem requires equals and hashCode to return the same result

You shouldn’t use the version in equals because after the save the version is changed

Okay, thank you. I removed it and everything works fine now. Lets hope nothing else breaks because of the removed version check xD

Equals and hashCode must return the same value during the lifetime of the object

Otherwise you will get problems with collections

You should also read about it in combination with JPA/Hibernate The best way to implement equals, hashCode, and toString with JPA and Hibernate - Vlad Mihalcea