Title: RE: Wierd CMR behavior

The JavaDoc for retainAll does not specify how the collection will compare the elements in the other collection - could use == or equals method.  The retainAll method probably uses the equals method and maybe the hashCode method to compare objects in the collections. 

The interface implementations from your provider probably don't implement these methods the way your are expecting them to, thus causing unequal comparisons.

James Hicks 

-----Original Message-----
From: Justin Wesbrooks [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 16, 2003 4:06 PM
To: [EMAIL PROTECTED]
Subject: Wierd CMR behavior


I have a CMP (beanA) with a 1 to many relationship with beanB, so beanA instance has a collection of beanB's.  The following pseudocode is what I do.

//**************************************************************************
//beanA.getBeanBs().size() equals 2 here
//I have a temp collection of BeanBs that I need to compare to //the real collection in beanA.  If I compare one bean at a time, //as in the following...

Iterator it = tmpColl.iterator();
while(it.hasNext()){
      BeanB beanb = (BeanB)it.next();
        //The following prints out TRUE for every bean
      System.out.println(beanA.getBeanBs().contains(beanb));
}

//so at this point, I know that all beans in the temp collection //are contained in the real collection

//i want to keep all beans in the temp collection in the real //collection and remove all beans in the real collection that //aren't in the temp collection.

beanA.getBeanBs().retainAll(tmpColl);
System.out.println(beanA.getBeanBs().size());
//This prints out "0" when it should print out 2  ????
//***************************************************************************

I can't figure out why it's removing both beans from the real collection when I just verified they exist in both collections.  I feel like there is some behavior with the retainAll() method that I'm not aware of that's throwing me off.  In addition to this, even though all beanBs are removed from beanA when I call retainAll(), they still remain in the underlying database??

Has anyone experienced this kind of behavior??

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff EJB-INTEREST".  For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination, or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you receive this in error, please contact the sender and delete the material from all computers.

Reply via email to