This article suggests a JPA
equals
hashcode
31
hashcode
//Load product1 and product2
Set<Product> products = new HashSet<>();
products.add(product1);
products.add(product2);
Set
hashcode
Definitely. See Class HashMap documentation. HashSet is backed by a HashMap, so this applies to HashSet too. See Class HashSet documentation.
To the second question, no. HashMap uses equality to decide whether an entity is equal. It will just be terribly inefficient since the map will degenerate to a linked list.