|
My use case is very simple, and it goes like this:
A have a Product parent association and an Image child association. Product contains a Set<Image>.
Here is what I did:
Product product = entityManager.find(Product.class, productId); assertEquals(2, product.getImages().size()); Iterator<Image> imageIterator = product.getImages().iterator();
Image frontImage = imageIterator.next(); assertEquals("front image", frontImage.getName()); Image sideImage = imageIterator.next(); assertEquals("side image", sideImage.getName());
assertTrue(new ArrayList<Image>(product.getImages()).contains(sideImage)); assertTrue(product.getImages().contains(sideImage));
If I wrap the images in an ArrayList<Image>, the sideImage can be found, but it can't be loaded from the PersistentSet.
My wild guess is that the PersistentSet calculates the hashCode prior to initializing the contained Entity, and when the Entity is initialized the hashCode changes as well, making it impossible to finding the loaded Entity.
|