Hibernate Books

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: "Java Persistence with Hibernate" mistake :(
PostPosted: Sun Apr 27, 2008 2:29 pm 
Newbie

Joined: Sun Apr 27, 2008 1:10 pm
Posts: 2
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.