-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Awkward Map.get() problem during validation
PostPosted: Fri Jun 18, 2010 11:34 am 
Newbie

Joined: Sun Feb 14, 2010 10:13 am
Posts: 17
Hello

I ran into this really awkward problem in Map.get() (implemented as HashMap proxied by PersistentMap).
I am calling myMap.get(myKey) but always get null, and myMap.keySet().contains(myKey) also returns false, although myKey is contained in it!
I inspected myMap to see if it contains myKey and indeed it is, and it is mapped to a non-null value. I could easily prove it by iterating over the Map:


Code:
public void myCheck() {
   for (MyKey k : myMap.keySet()) {
      System.out.println(myMap.containsKey(k));
   }
}

Although the loop is indeed entered for every k, myMap.contains(k) is never true. the result for my 2-keyed map is:
false
false

even myMap.containsKey(myMap.keySet().iterator().next()) returns false.

How is this even possible?
Perhaps it is a PersistentMap bug?

Please help
Yuval


Top
 Profile  
 
 Post subject: Re: Awkward Map.get() problem during validation
PostPosted: Mon Jun 21, 2010 5:30 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

this sounds indeed very strange. Make sure to check your hashCode and equals implementations. A buggy implementation there could maybe cause the problem.
If you think the implementations of these method are ok you can create a Jira issue and attach a test case.

--Hardy


Top
 Profile  
 
 Post subject: Re: Awkward Map.get() problem during validation
PostPosted: Mon Jun 21, 2010 10:02 am 
Newbie

Joined: Sun Feb 14, 2010 10:13 am
Posts: 17
Hello Hardy

looks like you were right - my hashCode implementation wasn't good enough, because i used my id field for hashCode() and equals(). I changed this and it works fine now, though, i can't really say what's wrong with that in my use case (creating a new entity) - the entity was already persisted so it had an id, in such case i don't understand why is it bad to return id.hashCode()

Anyway thanks for your help
Yuval


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

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.