Optimization a equals and hashcode methods for entities