Казалось бы, что тут все просто и тема давно изведана, но остается вопрос о instaceof vs getClass
"Never use the database identifier to implement equality. Instead, use a business key that is a combination of unique, typically immutable, attributes. The database identifier changes if a transient object is made persistent. If the transient instance, together with detached instances, is held in a
... подборка материала:- equals and hashCode for Dummies (Again)
- Equals and Hash Code
- Josh Bloch: Effective Java - Item 8
- Cay Horstmann: Some Objects are More Equal Than Others
"Never use the database identifier to implement equality. Instead, use a business key that is a combination of unique, typically immutable, attributes. The database identifier changes if a transient object is made persistent. If the transient instance, together with detached instances, is held in a
Set
, changing the hash-code breaks the contract of the
Set
. Attributes for business keys can be less stable than database primary keys. You only
need to guarantee stability as long as the objects are in the same Set
." (Hibernate ref)
Комментариев нет:
Отправить комментарий