| In my previous response, I forgot to link the proper blog post about using the PK as a substitute for a natural key: https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-entity-identifier/ This way, you always have a unique key for your equals/hashCode. Therefore, you never need to use a Collection for equality. As for Bags, they don't guarantee any order, just like any SQL statement that lacks an ORDER BY clause. Therefore, it's still not clear why this behavior is even causing you an issue. Using Collections for equality is actually a misusage pattern. |