You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Gary Jarrel <ga...@gmail.com> on 2010/07/29 07:46:28 UTC

Addings Objects to a To-Many Relationship

Hi All

I've noticed something interesting and although it seems trivial from
the outset, I am not sure why this happens:

MarketingCampaign campaign =
DataContext.getThreadObjectContext().newObject(MarketingCampaign.class);
MarketingCampaignProduct pT1 =
DataContext.getThreadObjectContext().newObject(MarketingCampaignProduct.class);

campaign.addToMarketingCampaignProducts(pT1);
campaign.addToMarketingCampaignProducts(pT1);

assertEquals(1, campaign.getMarketingCampaignProducts().size());

I would have though that adding the same object to the list would not
make the list grow however my assert fails because the list appears to
be of size 2 instead of 1.

Perhaps I am missing something here?

Thank you

Gary

Re: Addings Objects to a To-Many Relationship

Posted by Gary Jarrel <ga...@gmail.com>.
On Thu, Jul 29, 2010 at 3:55 PM, Andrey Razumovsky
<ra...@gmail.com> wrote:
> Hi,
>
> This is List after all :) You can use Set or Map as collection type if
> adding same objects to list is important
>

Hehehe I can't believe I just asked the question :) Definitely not
thinking clearly today

Thank you

Gary

Re: Addings Objects to a To-Many Relationship

Posted by Andrey Razumovsky <ra...@gmail.com>.
Hi,

This is List after all :) You can use Set or Map as collection type if
adding same objects to list is important

2010/7/29 Gary Jarrel <ga...@gmail.com>

> Hi All
>
> I've noticed something interesting and although it seems trivial from
> the outset, I am not sure why this happens:
>
> MarketingCampaign campaign =
> DataContext.getThreadObjectContext().newObject(MarketingCampaign.class);
> MarketingCampaignProduct pT1 =
>
> DataContext.getThreadObjectContext().newObject(MarketingCampaignProduct.class);
>
> campaign.addToMarketingCampaignProducts(pT1);
> campaign.addToMarketingCampaignProducts(pT1);
>
> assertEquals(1, campaign.getMarketingCampaignProducts().size());
>
> I would have though that adding the same object to the list would not
> make the list grow however my assert fails because the list appears to
> be of size 2 instead of 1.
>
> Perhaps I am missing something here?
>
> Thank you
>
> Gary
>



-- 
Andrey