OObjectLazySet duplicate entries
Hi,
I'm trying to store an object a of type A with a set of elements inside of type B.
hashcode and equals methods in my type B are defined as following
@Override
public int hashCode() {
return 1;
}
@Override
public boolean equals(Object obj) {
return true;
}
In my code(pseudo) I do the following:
B b=new B();
A a=db.load("
Running this test multiple times the db keep adding elements to the set although B identity semantic is saying that all B instances are identical.
Thanks
@MaDaPHaKa have you any idea why it happens?
Fixed in commit 4344328a658114c46938bd85a7b5229c3854974f (branch hotfix-1.4.2)
Hi, there are still problems about set duplication. I'm commenting this closed issue rather than opening a new one and I let you decide whether reopening it or not.
I've downloaded your fix from the hotfix1.4.2 branch, compiled and installed in my local repo to replace the 1.4.1.
I've replaced only the orientdb-object jar, the one containing the fixed class.
To simplify the description of the problem I've created two minimal versions of hashcode and equals. The semantic is: All the objects in the set are equals if they belong to the same class(a simplified version of the standard equals semantic).
@Override
public int hashCode() {
return 1;
}
@Override
public boolean equals(Object obj) {
if (!this.getClass().equals(obj.getClass())) {
log.debug(
"Unexpected: returning false. this.getClass():{} - obj.getClass():{}",
this.getClass(), obj.getClass());
return false;
}
log.debug(
"Expected: returning true. this.getClass():{} - obj.getClass():{}",
this.getClass(), obj.getClass());
return true;
}
This is what I get when I run the test the second time:
//The Class already contains a persisted element and the size of the lazySet is 1 //Then I add a newly created object to the lazy set //here I get the unexpected behavior. The incoming object (not proxied) is added to a set of underlying proxied objects and the equals fails when comparing classes DEBUG org.photoni.model.SyndFeedDocument.equals(SyndFeedDocument.java:138) Unexpected: returning false. this.getClass():class org.photoni.model.SyndFeedDocument - obj.getClass():class org.photoni.model.SyndFeedDocument_$$_javassist_1 //The new size of the lazy set is 2 DEBUG org.photoni.rss.RSSAggregator.aggregate(RSSAggregator.java:94) Persisting 2 entries for feed in set implementation com.orientechnologies.orient.object.db.OObjectLazySet
//here the already converted objects are added to another set, probably when flushing changes to the db. The method equals is called againg,this time with success, but too late
DEBUG org.photoni.model.SyndFeedDocument.equals(SyndFeedDocument.java:143) Expected: returning true. this.getClass():class org.photoni.model.SyndFeedDocument_$$javassist_1 - obj.getClass():class org.photoni.model.SyndFeedDocument$$javassist_1 DEBUG org.photoni.model.SyndFeedDocument.equals(SyndFeedDocument.java:143) Expected: returning true. this.getClass():class org.photoni.model.SyndFeedDocument$$javassist_1 - obj.getClass():class org.photoni.model.SyndFeedDocument$$_javassist_1
//the standard equals semantic is broken by javassist runtime proxyes
Regards
Hi,
the only way to manage this would be to:
- check if the Set contains the non wrappet object,
- wrap around a proxy a non-proxied instance added, check if the set contains it
- if not add the original one (that will be proxied again when saved). All of that because wrap around the proxy the original instance and add it would mean that all modifications won't be replicated in the proxied one.
It seems to much overhead to me :) I think the best way is to use the db.newInstance() API or manage the proxied object case in the equals().
Hi, I don't have any problem in managing it in my code, it's not blocking my work so far. I've posted the issue, because identity management is the foundation of a data modeling and coupling the code to the logic of your system can be a limitation in the adoption, especially by those architects addicted to JPA/Hibernate. It's a sin cause I think that your db is a fantastic product Thanks for your quick answer Regards