hi,
 
thanks for the solution, i really feared that this might be the solution.

what i expected from OJB is that my code has nothing OJB specific in it
(beside peristent specific things lke store, retrieve, delete) and that i
can use beans as i always use them.
if i need to implement equals() and hashCode(), i'll have to add code that's
only there because i use OJB (and one of its functionalitites, dynamic
proxies). and, to be honest, this makes me quite unhappy. isn't there any
other solution out there?

kr,
guenther

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Monday, May 02, 2005 6:21 PM
To: OJB Users List
Subject: Re: problem with lists in n:m relation and proxy=dynamic

You need to implement equals() in your Pharmacy implementation class. 
What's happening is that either the object in the collection or the object
that you're passing to remove() is a Proxy.  The default implementation of
equals() (which is used by remove()) just uses ==.  Since the objects are
not the same object, remove() doesn't find the one you're trying to get rid
of.

Here's a sample implementation (for a PharmacyImpl class implementing a
Pharmacy interface - adjust names as necessary):

public boolean equals(Object o) {
    if (o == null) return false;
    if (o == this) return true;

    // Double-dispatch to remove any Proxy from the picture
    if (java.lang.reflect.Proxy.isProxyClass(o.getClass())) {
        return o.equals(this);
    }

    if (! getClass().equals(o.getClass())) return false;

    PharmacyImpl p = (PharmacyImpl) o;
    // compare two PharmacyImpl's this and p }

Also, be sure to implement hashCode() as well.  It needs to return a value
which is consistent with equals() - i.e. two objects which are equals()
should have the same hashCode().

-steve

Steve Clark
ECOS Development Group
[EMAIL PROTECTED]
(970)226-9291




G�nther Wieser <[EMAIL PROTECTED]>
05/02/2005 04:15 AM
Please respond to
"OJB Users List" <[email protected]>


To
"'OJB Users List'" <[email protected]>
cc

Subject
problem with lists in n:m relation and proxy=dynamic






hi,

i've two classes that are linked to each other (bi-directional) using an
indeirection table. they are called "pharmacy" and "campaign", and 
pharmacy
has a method "List getCampaigns()" to retreive all campaigns it is in, and
campaign has a method "List getPharmacies()", which gives back the list of
pharmacies that participate in this campaign.

when i need to remove one pharmacy from a campaign, i do the following:

boolean campRemoveResult = campaign.getPharmacies().remove(pharmacy);
boolean pharmRemoveResult = pharmacy.getCampaigns().remove(campaign);

then i store both of the them to have my changes persistet. i can see in 
the
database that the entry in the indirection table has beem removed.

BUT: pharmRemoveResult is TRUE, but campRemoveResult = FALSE, and the list
"campaign.getPharmacies()" still contains the pharmacy i just removed.
so far i found out that the pharmacy object linked to the list in campaign
is somehow different to the pharmacy object i have during runtime. if i do 
a
toString() on the pharmacy i have and the pharmacy i found in the pharmacy
list of camaign (searched for the same primary key), the both have the 
same
object id and all the values AND references to other objects are the same.
still, the "equals()" method returns false.

pharmacy has "proxy=dynamic", and if i remove this, everything works fine.
but this is of course no solution for my problem.

anyone an idea how to successfully remove objects from a list if the only
object that should be removed has proxy=dynamic? am i doing something
fundamentally wrong here?


kr,
guenther




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to