-->
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.  [ 1 post ] 
Author Message
 Post subject: PersistentMap strabge behaviour
PostPosted: Tue Dec 04, 2007 7:06 am 
Newbie

Joined: Tue Dec 04, 2007 6:24 am
Posts: 13
Hi folks,

I am facing a strange problem I can not figure out. Maybe you guys can give an explaination (or better, a fix!).

I have a class A that holds a map of class B for values, class K is used for keys :

public class A extends BaseObject implements Serializable {
private Map<K, B> m = new HashMap<K, B>();

public B getValue(String aString){
K key = new K();
k.setString(aString);
return m.get(k);
}
...
}

I have written a custom hashcode() method for the class K which is based on the getString() method only. So 2 different instances of K will have the same hashCode() result provided they have the same getString() result.

Now here is a simple test case :

public class MyTest extends AbstractTransactionalDataSourceSpringContextTests{
private ADao adao;
private KDao kdao;
public void setADao(ADao dao) {this.adao = dao;}
public void setKDao(KDao dao) {this.kdao = dao;}

public void testFails() throws Exception {
A a = adao.get(1L);
assertnotNull(a.getValue("foo")); // Fails!
}

public void testSuccessfull() throws Exception {
A a = adao.get(1L);
K k = kdao.getK("foo");
assertnotNull(a.getValue("foo"));
}

}

the first one fails whereas the second one is successfull... The only difference between them is that I load the K instance from DB before accessing the map (but I don't use this loaded object). Is there a reason for that?

Any explaination is warmly welcome.
Thanks.


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.