This article suggests a JPA
//Load product1 and product2
Set<Product> products = new HashSet<>();
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.