-->
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.  [ 5 posts ] 
Author Message
 Post subject: Equals method and collections
PostPosted: Mon Feb 14, 2005 10:14 am 
Beginner
Beginner

Joined: Wed Jan 26, 2005 5:34 am
Posts: 41
Location: France, Paris
Hibernate version: Hibernate3 beta4b

Mapping documents:
Code:
    <bag name="phoneNumbers" table="phone" cascade="all-delete-orphan">
      <key column="msl_id" not-null="true"/>
      <element column="pho_phone" type="string" length="255" not-null="true"/>
    </bag>


Code between sessionFactory.openSession() and session.close():

Code:
(snip)
            ses.addPhoneNumber("+33 123456789 (Me)");
            ses.addPhoneNumber("+33 123456789 (You)");
            ses.addPhoneNumber("+33 123456789 (Other)");
            assertEquals(ses.getEmails().size(),2);
(snip)
            hSession.clear();

            transaction = hSession.beginTransaction();
            storedSes = (Session)hSession.load(Session.class, ses.getSQLId());
            assertNotNull(storedSes);
            assertEquals(ses.getPhoneNumbers(), storedSes.getPhoneNumbers());


Why ses.getPhoneNumbers().equals(storedSes.getPhoneNumbers()) returns false ?

Code:
    public Collection<String> getPhoneNumbers() {
        return this.phoneNumbers;
    }

_________________
Vincent


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 11:34 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
year, I had this discussion before with Gavin... and failed to convince it :-)
We choose not to respect the Collection semantic for Bags since it implies loading the full collections to correctly implement it.
It is a bad practice to compare collections, anyway.

Since Bag is now the base implementation of our EJB3 API, I would be incline to fix it... if I figure how to convince Gavin

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 11:41 am 
Beginner
Beginner

Joined: Wed Jan 26, 2005 5:34 am
Posts: 41
Location: France, Paris
emmanuel wrote:
year, I had this discussion before with Gavin... and failed to convince it :-)
We choose not to respect the Collection semantic for Bags since it implies loading the full collections to correctly implement it.

Ok... so.. if i use list, that will work ? :)

emmanuel wrote:
It is a bad practice to compare collections, anyway.

Why ? (i'm not a java guru) I missed a specification ?
To me, 2 collections are equals if all elements are 'equals', aren't ?

emmanuel wrote:
Since Bag is now the base implementation of our EJB3 API, I would be incline to fix it... if I figure how to convince Gavin

Good luck ;-)

_________________
Vincent


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 11:54 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Everything but Bags will work.

What is you particular use case for doing such mass comparison in a ORM environment?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 12:00 pm 
Beginner
Beginner

Joined: Wed Jan 26, 2005 5:34 am
Posts: 41
Location: France, Paris
emmanuel wrote:
Everything but Bags will work.

What is you particular use case for doing such mass comparison in a ORM environment?


I just tested, i prepared some JUnit test case, and assertEquals failed. So, i wanted know why :) I've no particular use case for the moment. I like understand :)

_________________
Vincent


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