private boolean hasSameBusinessSignature(HibernateEntity<TId> other) { boolean notNull = (other != null); int hash = (getId() != null) ? HashTool.compute(getId()) : hashCode(); if (notNull) { int otherHash = (other.getId() != null) ? HashTool.compute(other.getId()) : other.hashCode(); return hash == otherHash; } return false; }
@Override @SuppressWarnings("unchecked") public boolean equals(Object obj) { boolean isSampeType = (obj != null) && getClass().equals(obj.getClass()); if (isSampeType) { HibernateEntity<TId> entity = (HibernateEntity<TId>) obj; return hasSameNonDefaultIdAs(entity) || ((!isPersisted() || !entity.isPersisted()) && hasSameBusinessSignature(entity)); } return false; }
private boolean hasSameNonDefaultIdAs(HibernateEntity<TId> entity) { if (entity == null) return false; TId id = getId(); TId entityId = entity.getId(); return (id != null) && (entityId != null) && (id.equals(entityId)); }