Corrected the equals/hascode of generated entities

Check the ID value and not just the reference

Fix #616
Corrected wrong variable name