-->
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.  [ 4 posts ] 
Author Message
 Post subject: remove(), contains() etc. not working correctly
PostPosted: Thu Jan 22, 2004 3:23 pm 
Beginner
Beginner

Joined: Thu Oct 30, 2003 6:29 am
Posts: 30
Location: Germany, KA
hi,
problem: after hibernate cached a set of objects, i have problems with comparing:

Session1:
--
group = hibSess.load(XBO_CLASS, "12345");
groups.add(group);
--

Session2:
--
group = hibSess.load(XBO_CLASS, "12345");
if (groups.contains(group)) {
logger.debug("works!");
}
--


When starting my Application this works fine, when invoking this method the second time, it doesn't!

the follwing works fine all the time:
--
group = hibSess.load(XBO_CLASS, "12345");
Iterator i = groups.iterator();
while (i.hasNext()) {
Group workaround = (Group) i.next();
if (groups.contains(group)) {
logger.debug("works!");
}
}


s.th. because of lazy-init? I do not want to turn it off.
a bug?

thanks, marie


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 5:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
How does your equal, hasCode look like?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 6:19 am 
Beginner
Beginner

Joined: Thu Oct 30, 2003 6:29 am
Posts: 30
Location: Germany, KA
XBGroup extends XinityBaseObject

class XinityBaseObject {
...
public boolean equals(Object o) {
if (!(o instanceof XinityBaseObject))
return false;

String idThis = getUid();
String idO = ((XinityBaseObject)o).getUid();

if (idThis != null) {
return idThis.equals(idO);
} else if (idO != null) {
return false;
} else {
throw new IllegalStateException ("id is null! can't compare objects");
}
}
}

I did not overwrite hashCode(). I can't check wether this is the problem at the moment (no access to actual code).
Indeed, the debugger shows diffrent JVM identities of the group as reference and the group within the Collection. But he should use the equals-method, should't he?
If I implement the hashCode(), would s.th. like "return this.getUid()" be enough? What if the id is null? Than I can't tell the hashCode. Is throwing the IllegalStateException ok?

thank you


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 6:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Of course you have to implement hashCode. Your Set ist most likely a HashSet ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.