Hi All !
I'm reading wonderful book named
"Java Persistence with Hibernate"(G.King) and found some mistake :(
3.4.1 Creating dynamic applications
In article
Working with dynamic maps we have next example:
Code:
Map user = new HashMap();
user.put("username", "johndoe");
Map item1 = new HashMap();
item1.put("description", "An item for auction");
item1.put("initialPrice", new BigDecimal(99));
item1.put("seller", user);
Map item2 = new HashMap();
item2.put("description", "Another item for auction");
item2.put("initialPrice", new BigDecimal(123));
item2.put("seller", user);
Collection itemsForSale = new ArrayList();
itemsForSale.add(item1);
itemsForSale.add(item2);
user.put("itemsForSale", itemsForSale);
session.save("UserEntity", user);
and next FAQ:
Quote:
Can I map a Set in dynamic mode? Collections based on sets don’t work
with dynamic entity mode. In the previous code example, imagine that
itemsForSale was a Set. A Set checks its elements for duplicates, so
when you call add(item1) and add(item2), the equals() method on
these objects is called. However, item1 and item2 are Java Map instances,
and the equals() implementation of a map is based on the key sets of
the map. So, because both item1 and item2 are maps with the same keys,
they aren’t distinct when added to a Set. Use bags or lists only if you
require collections in dynamic entity mode.
I know that equivalence at java maps are not constructed only on equivalence of keys but also on values under these keys
In this case and in case of example above, values item1 and item2 are not equal.
I think, that we have mistake in this book and may be we have mistake in hibernate realization..
We need to check this.
Thanks,
Alexander