Craig L Russell wrote:
Hi Mitesh,
...we can generate and assign a UUID in constructor of the pojos. We
can use UUID generator based on JavaSE 5 or use one bundled with
apache commons
(http://jakarta.apache.org/commons/sandbox/id/apidocs/org/apache/commons/id/uuid/UUID.html)
+1
Until all persistence providers support UUID generation as part of their
feature set, I think it makes sense for Roller to generate the id and
give it to the persistence provider. 100% portable and using the Apache
code makes it pre-1.5 compatible.
I am fine with generating our own UUIDs, assuming that there is no way
for upgrading users to run into problems, but I'm not sure about using
them in the equals() and hashCode() implementations.
WebsiteData w1 = new WebsiteData(handle="foo");
WebsiteData w2 = new WebsiteData(handle="foo");
w1.equals(w2);
If ids are generated and used for equals() and hashCode() instead of
real business keys like we are trying to do now then the statement above
would be false, which is wrong, right?
-- Allen
Craig
On Jan 24, 2007, at 2:50 PM, Mitesh Meswani wrote:
Allen Gilliland wrote:
I agree, and in general any object which is associated with a
specific weblog should probably be using the website in its equals()
and hashCode() methods. So maybe the what really needs to happen is
to revert revision 499419 which removes those comparisons from the
Folder and Category objects.
Revision 499419 is a workaround for a toplink issue. From the comments
in previous version of code ("NOTE: currently we are implementing
equals only using the path of the folder. technically the business
key should be for both the weblog & path, but we don't expect to be
comparing folders from 2 different weblogs so this should be fine"), I
think the workaround should be ok for now.
While we are on issue of equals() and hashcode() - Currently the impls
of this methods use couple of fields that are mutable (e.g FolderData
uses path which will change if a folder is moved or renamed). I think
it is not a good idea to have any mutable field as part of the
calculation. If the field is mutated after the pojo is placed in a
collection (almost all the persistence providers use them for caching)
we might get into issues that are hard to debug.
I think we require current form of equals() and hashcode() that uses
couple of fields instead of pk of the object for equality because we
are using generated ids. I am proposing that we switch to user
supplied ids. Instead of hibernate generating a UUID and assigning it
at insert time, we can generate and assign a UUID in constructor of
the pojos. We can use UUID generator based on JavaSE 5 or use one
bundled with apache commons
(http://jakarta.apache.org/commons/sandbox/id/apidocs/org/apache/commons/id/uuid/UUID.html)
What do others think?
Thanks,
Mitesh
-- Allen
Mitesh Meswani wrote:
Hi Dave,
I don't think this is a workaround. At least during the test I came
across instances of RefererData that belonged to different website
but where refererUrl was equal and weblogEntry was null. Is that
not a probable scenario?
Regards,
Mitesh
[EMAIL PROTECTED] wrote:
Author: snoopdave
Date: Wed Jan 24 06:36:15 2007
New Revision: 499420
URL: http://svn.apache.org/viewvc?view=rev&rev=499420
Log:
Add website to equals() and hashCode(), which is redundant but
allows us to work around a JPA issue.
Modified:
incubator/roller/trunk/src/org/apache/roller/pojos/RefererData.java
Modified:
incubator/roller/trunk/src/org/apache/roller/pojos/RefererData.java
URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/RefererData.java?view=diff&rev=499420&r1=499419&r2=499420
==============================================================================
---
incubator/roller/trunk/src/org/apache/roller/pojos/RefererData.java
(original)
+++
incubator/roller/trunk/src/org/apache/roller/pojos/RefererData.java
Wed Jan 24 06:36:15 2007
@@ -438,6 +438,7 @@
return new EqualsBuilder()
.append(getRefererUrl(),
o.getRefererUrl()) .append(getWeblogEntry(),
o.getWeblogEntry()) + .append(getWebsite(),o.getWebsite())
.isEquals();
}
@@ -445,6 +446,7 @@
return new HashCodeBuilder()
.append(getRefererUrl())
.append(getWeblogEntry())
+ .append(getWebsite())
.toHashCode();
}
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:[EMAIL PROTECTED]
P.S. A good JDO? O, Gasp!