Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » CDO Duplicate ID problem or misuse?
CDO Duplicate ID problem or misuse? [message #424247] Tue, 21 October 2008 16:07 Go to next message
Stephen McCants is currently offline Stephen McCantsFriend
Messages: 92
Registered: July 2009
Member
Hello,

I tried to solve a problem two different ways and finally came to a third solution. I have a
question about why the first two failed and if they should have failed (i.e. I'm misusing CDO).
First, I have two models. The first model has a non-containment reference to an object in the
second model. In my unit testing, I create the first model and the second model. Then I connect
the first model to the second model through the non-containment reference and then test my business
logic against the models.

Here is the first thing I tried:

1)Create a CDO repository
2)Create a CDO session
3)Create a CDO transaction
4)Create/Get a resource to hold the first model.
5)Create the first model (without any references to other models) and add it to the resource.
6)Commit the transaction.
7)Create/Get a second resource to hold the second model.
8)Create the second model and add it to the second resource.
9)Commit the transaction.
10)Add an object to the first model that has a non-containment reference to the second model.
11)Commit the transaction.

On step 11, I get a duplicate ID exception. Should I be able to do this, or must I create the
second model in a different transaction?

Here is the second thing I tried:

1.Create a CDO repository
2.Create a CDO session
3.Create a CDO transaction
4.Create/Get a resource to hold the first model.
5.Create the first model (without any references to other models) and add it to the resource.
6.Commit the transaction.
7.Create a second transaction.
8.Create/Get a second resource from the second transaction.
9.Create the second model and add it to the second resource.
10.Commit the second transaction transaction.
11.Add an object to the first model that has a non-containment reference to the second model.
12.Commit the transaction.

This generates a different error, a NullPointerException in net4j. Should this work or is it a bad
idea to mix objects from different transactions/views?

Here is the third thing I tried that worked:

1.Create a CDO repository
2.Create a CDO session
3.Create a CDO transaction
4.Create/Get a resource to hold the first model.
5.Create the first model (without any references to other models) and add it to the resource.
6.Commit the transaction.
7.Create a second transaction.
8.Create/Get a second resource from the second transaction.
9.Create the second model and add it to the second resource.
10.Commit the second transaction transaction.
11.Get the second model from the first transaction.
12.Add an object to the first model that has a non-containment reference to the second model object
fetch through the first transaction.
13.Commit the transaction.

This works, since I'm not taking a pointer from the second transaction and trying to use it in the
first transaction.

My question is should the first two cases have worked? Especially the first one (I can imagine how
mixing objects from different transactions could cause real problems).

If you have any questions or would like real code instead of pseudo code, please let me know.

Thanks for all your help!

Sincerely,

Stephen McCants
Re: CDO Duplicate ID problem or misuse? [message #424259 is a reply to message #424247] Tue, 21 October 2008 17:09 Go to previous messageGo to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
While I'm reading and understanding your situation can you provide me which
version of CDO are you using ?



"Stephen McCants" <stephenmccants@yahoo.com> wrote in message
news:gdkunv$i4$1@build.eclipse.org...
> Hello,
>
> I tried to solve a problem two different ways and finally came to a third
> solution. I have a question about why the first two failed and if they
> should have failed (i.e. I'm misusing CDO). First, I have two models. The
> first model has a non-containment reference to an object in the second
> model. In my unit testing, I create the first model and the second model.
> Then I connect the first model to the second model through the
> non-containment reference and then test my business logic against the
> models.
>
> Here is the first thing I tried:
>
> 1)Create a CDO repository
> 2)Create a CDO session
> 3)Create a CDO transaction
> 4)Create/Get a resource to hold the first model.
> 5)Create the first model (without any references to other models) and add
> it to the resource.
> 6)Commit the transaction.
> 7)Create/Get a second resource to hold the second model.
> 8)Create the second model and add it to the second resource.
> 9)Commit the transaction.
> 10)Add an object to the first model that has a non-containment reference
> to the second model.
> 11)Commit the transaction.
>
> On step 11, I get a duplicate ID exception. Should I be able to do this,
> or must I create the second model in a different transaction?
>
> Here is the second thing I tried:
>
> 1.Create a CDO repository
> 2.Create a CDO session
> 3.Create a CDO transaction
> 4.Create/Get a resource to hold the first model.
> 5.Create the first model (without any references to other models) and add
> it to the resource.
> 6.Commit the transaction.
> 7.Create a second transaction.
> 8.Create/Get a second resource from the second transaction.
> 9.Create the second model and add it to the second resource.
> 10.Commit the second transaction transaction.
> 11.Add an object to the first model that has a non-containment reference
> to the second model.
> 12.Commit the transaction.
>
> This generates a different error, a NullPointerException in net4j. Should
> this work or is it a bad idea to mix objects from different
> transactions/views?
>
> Here is the third thing I tried that worked:
>
> 1.Create a CDO repository
> 2.Create a CDO session
> 3.Create a CDO transaction
> 4.Create/Get a resource to hold the first model.
> 5.Create the first model (without any references to other models) and add
> it to the resource.
> 6.Commit the transaction.
> 7.Create a second transaction.
> 8.Create/Get a second resource from the second transaction.
> 9.Create the second model and add it to the second resource.
> 10.Commit the second transaction transaction.
> 11.Get the second model from the first transaction.
> 12.Add an object to the first model that has a non-containment reference
> to the second model object fetch through the first transaction.
> 13.Commit the transaction.
>
> This works, since I'm not taking a pointer from the second transaction and
> trying to use it in the first transaction.
>
> My question is should the first two cases have worked? Especially the
> first one (I can imagine how mixing objects from different transactions
> could cause real problems).
>
> If you have any questions or would like real code instead of pseudo code,
> please let me know.
>
> Thanks for all your help!
>
> Sincerely,
>
> Stephen McCants
Re: CDO Duplicate ID problem or misuse? [message #424261 is a reply to message #424247] Tue, 21 October 2008 17:39 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Hi Stephen,

I'm currently abroad and don't have too much time available to
investigate your concrete problem (and Simon already jumped in).
But I think it's important to clarify a general aspect: All the EObjects
that you access through a certain instance of a CDOView or
CDOTransaction are really only meaningfull in the context of that
particular CDOView or CDOTransaction. You should not reference them
directly from other views or transactions. In case you're using CDO from
HEAD there's a special version of CDOView.getObject() that is able to
"contextualize" an object from one iew into another view (of the same
session!).

Cheers
/Eike



Stephen McCants schrieb:
> Hello,
>
> I tried to solve a problem two different ways and finally came to a
> third solution. I have a question about why the first two failed and
> if they should have failed (i.e. I'm misusing CDO). First, I have two
> models. The first model has a non-containment reference to an object
> in the second model. In my unit testing, I create the first model and
> the second model. Then I connect the first model to the second model
> through the non-containment reference and then test my business logic
> against the models.
>
> Here is the first thing I tried:
>
> 1)Create a CDO repository
> 2)Create a CDO session
> 3)Create a CDO transaction
> 4)Create/Get a resource to hold the first model.
> 5)Create the first model (without any references to other models) and
> add it to the resource.
> 6)Commit the transaction.
> 7)Create/Get a second resource to hold the second model.
> 8)Create the second model and add it to the second resource.
> 9)Commit the transaction.
> 10)Add an object to the first model that has a non-containment
> reference to the second model.
> 11)Commit the transaction.
>
> On step 11, I get a duplicate ID exception. Should I be able to do
> this, or must I create the second model in a different transaction?
>
> Here is the second thing I tried:
>
> 1.Create a CDO repository
> 2.Create a CDO session
> 3.Create a CDO transaction
> 4.Create/Get a resource to hold the first model.
> 5.Create the first model (without any references to other models) and
> add it to the resource.
> 6.Commit the transaction.
> 7.Create a second transaction.
> 8.Create/Get a second resource from the second transaction.
> 9.Create the second model and add it to the second resource.
> 10.Commit the second transaction transaction.
> 11.Add an object to the first model that has a non-containment
> reference to the second model.
> 12.Commit the transaction.
>
> This generates a different error, a NullPointerException in net4j.
> Should this work or is it a bad idea to mix objects from different
> transactions/views?
>
> Here is the third thing I tried that worked:
>
> 1.Create a CDO repository
> 2.Create a CDO session
> 3.Create a CDO transaction
> 4.Create/Get a resource to hold the first model.
> 5.Create the first model (without any references to other models) and
> add it to the resource.
> 6.Commit the transaction.
> 7.Create a second transaction.
> 8.Create/Get a second resource from the second transaction.
> 9.Create the second model and add it to the second resource.
> 10.Commit the second transaction transaction.
> 11.Get the second model from the first transaction.
> 12.Add an object to the first model that has a non-containment
> reference to the second model object fetch through the first transaction.
> 13.Commit the transaction.
>
> This works, since I'm not taking a pointer from the second transaction
> and trying to use it in the first transaction.
>
> My question is should the first two cases have worked? Especially the
> first one (I can imagine how mixing objects from different
> transactions could cause real problems).
>
> If you have any questions or would like real code instead of pseudo
> code, please let me know.
>
> Thanks for all your help!
>
> Sincerely,
>
> Stephen McCants


Re: CDO Duplicate ID problem or misuse? [message #424264 is a reply to message #424247] Tue, 21 October 2008 17:56 Go to previous messageGo to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
"Stephen McCants" <stephenmccants@yahoo.com> wrote in message
news:gdkunv$i4$1@build.eclipse.org...
> Hello,
>
> I tried to solve a problem two different ways and finally came to a third
> solution. I have a question about why the first two failed and if they
> should have failed (i.e. I'm misusing CDO). First, I have two models. The
> first model has a non-containment reference to an object in the second
> model. In my unit testing, I create the first model and the second model.
> Then I connect the first model to the second model through the
> non-containment reference and then test my business logic against the
> models.
>
> Here is the first thing I tried:
>
> 1)Create a CDO repository
> 2)Create a CDO session
> 3)Create a CDO transaction
> 4)Create/Get a resource to hold the first model.
> 5)Create the first model (without any references to other models) and add
> it to the resource.
> 6)Commit the transaction.
> 7)Create/Get a second resource to hold the second model.
> 8)Create the second model and add it to the second resource.
> 9)Commit the transaction.
> 10)Add an object to the first model that has a non-containment reference
> to the second model.
> 11)Commit the transaction.
>
> On step 11, I get a duplicate ID exception. Should I be able to do this,
> or must I create the second model in a different transaction?

You should be able to do that. I will build a testcase but I'm really
surprised that it doesn't

>
> Here is the second thing I tried:
>
> 1.Create a CDO repository
> 2.Create a CDO session
> 3.Create a CDO transaction
> 4.Create/Get a resource to hold the first model.
> 5.Create the first model (without any references to other models) and add
> it to the resource.
> 6.Commit the transaction.
> 7.Create a second transaction.
> 8.Create/Get a second resource from the second transaction.
> 9.Create the second model and add it to the second resource.
> 10.Commit the second transaction transaction.
> 11.Add an object to the first model that has a non-containment reference
> to the second model.
> 12.Commit the transaction.
>
> This generates a different error, a NullPointerException in net4j. Should
> this work or is it a bad idea to mix objects from different
> transactions/views?

It is a bad idea to uses different objects from differents transactions if
they are from the same repository.
(It is possible to use them if they do not belong to the same repository)
see:
http://wiki.eclipse.org/New_And_Noteworthy_for_CDO_2.0#Suppo rt_external_references


>
> Here is the third thing I tried that worked:
>
> 1.Create a CDO repository
> 2.Create a CDO session
> 3.Create a CDO transaction
> 4.Create/Get a resource to hold the first model.
> 5.Create the first model (without any references to other models) and add
> it to the resource.
> 6.Commit the transaction.
> 7.Create a second transaction.
> 8.Create/Get a second resource from the second transaction.
> 9.Create the second model and add it to the second resource.
> 10.Commit the second transaction transaction.
> 11.Get the second model from the first transaction.
> 12.Add an object to the first model that has a non-containment reference
> to the second model object fetch through the first transaction.
> 13.Commit the transaction.
>
> This works, since I'm not taking a pointer from the second transaction and
> trying to use it in the first transaction.
>
> My question is should the first two cases have worked? Especially the
> first one (I can imagine how mixing objects from different transactions
> could cause real problems).
>
The first one should really work. Until I have the version of CDO you are
using I will assume it is HEAD. :-)
I will come up with case 1 as a testcase (we probably have many of
them!!:-))

> If you have any questions or would like real code instead of pseudo code,
> please let me know.
>
> Thanks for all your help!
>
> Sincerely,
>
> Stephen McCants
Re: CDO Duplicate ID problem or misuse? [message #424269 is a reply to message #424264] Tue, 21 October 2008 18:47 Go to previous messageGo to next message
Stephen McCants is currently offline Stephen McCantsFriend
Messages: 92
Registered: July 2009
Member
Hi Simon,
I'm using 2.0.0.200810082259. I have a deliverable at the end of the month and then we are
planning to move to whatever the latest from HEAD is at that time. Thank you (and Eike as well) for
the explanation of why #2 didn't work.
If you need/want anything else from me, please let me know.
Thanks for your help!

--Stephen
Re: CDO Duplicate ID problem or misuse? [message #424270 is a reply to message #424261] Tue, 21 October 2008 18:50 Go to previous messageGo to next message
Stephen McCants is currently offline Stephen McCantsFriend
Messages: 92
Registered: July 2009
Member
Hello Eike,

> But I think it's important to clarify a general aspect: All the EObjects
> that you access through a certain instance of a CDOView or
> CDOTransaction are really only meaningfull in the context of that
> particular CDOView or CDOTransaction. You should not reference them
> directly from other views or transactions.

Good to know. Thanks for the clarification.

> In case you're using CDO from
> HEAD there's a special version of CDOView.getObject() that is able to
> "contextualize" an object from one iew into another view (of the same
> session!).

I'll keep that in mind in case I need it.

Thank you (and Simon) for all your help. You both are very helpful and CDO is great!

Sincerely,
Stephen
Re: CDO Duplicate ID problem or misuse? [message #424271 is a reply to message #424269] Tue, 21 October 2008 18:53 Go to previous messageGo to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
Can we have the stack trace ?

Does the duplicate object is a Resource ?

In the following bugzilla:
248915: Resources fetched using CDOViewImpl.getResource(CDOID) not added to
ResourceSet
https://bugs.eclipse.org/bugs/show_bug.cgi?id=248915

It happens also that the Resource is being added multiple times resulting of
a duplicate ID. It is fixed but you will need to upgrade.
(Warning: many others things changed in HEAD).
I think you could apply the patch v2 on that bug to fix your issue.

If it is not the resource the problem... this will not fix your problem.

Let me know if it is a resource and if it is possible the stack trace!

Thank you!




"Stephen McCants" <stephenmccants@yahoo.com> wrote in message
news:48FE23A5.9080305@yahoo.com...
> Hi Simon,
> I'm using 2.0.0.200810082259. I have a deliverable at the end of the
> month and then we are planning to move to whatever the latest from HEAD is
> at that time. Thank you (and Eike as well) for the explanation of why #2
> didn't work.
> If you need/want anything else from me, please let me know.
> Thanks for your help!
>
> --Stephen
Re: CDO Duplicate ID problem or misuse? [message #424304 is a reply to message #424271] Wed, 22 October 2008 15:57 Go to previous messageGo to next message
Stephen McCants is currently offline Stephen McCantsFriend
Messages: 92
Registered: July 2009
Member
Hi Simon,
I went back to reproduce the problem and I was unable to reproduce the error, even though I
followed my own instructions. I'm not sure if there was something else that I didn't document that
might have been causing the problem.
Either way, you might want to take this with a grain of salt... I don't want to send you on a wild
goose chase.
Thanks for your help.

--Stephen

Simon McDuff wrote:
> Can we have the stack trace ?
>
> Does the duplicate object is a Resource ?
>
> In the following bugzilla:
> 248915: Resources fetched using CDOViewImpl.getResource(CDOID) not added
> to ResourceSet
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=248915
>
> It happens also that the Resource is being added multiple times
> resulting of a duplicate ID. It is fixed but you will need to upgrade.
> (Warning: many others things changed in HEAD).
> I think you could apply the patch v2 on that bug to fix your issue.
>
> If it is not the resource the problem... this will not fix your problem.
>
> Let me know if it is a resource and if it is possible the stack trace!
>
> Thank you!
>
>
>
>
> "Stephen McCants" <stephenmccants@yahoo.com> wrote in message
> news:48FE23A5.9080305@yahoo.com...
>> Hi Simon,
>> I'm using 2.0.0.200810082259. I have a deliverable at the end of the
>> month and then we are planning to move to whatever the latest from
>> HEAD is at that time. Thank you (and Eike as well) for the
>> explanation of why #2 didn't work.
>> If you need/want anything else from me, please let me know.
>> Thanks for your help!
>>
>> --Stephen
>
Re: CDO Duplicate ID problem or misuse? [message #424306 is a reply to message #424304] Wed, 22 October 2008 16:15 Go to previous message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
I'm almost sure it was the problem mentionned in bugs
>> 248915: Resources fetched using CDOViewImpl.getResource(CDOID) not
>> added to ResourceSet
Basically to reproduce it you need

In this example:

ResourceA
|_____objectA

You need in a transaction create the following structure:
ResourceA
|_____objectA

Commit.
From another transaction:

view.getObject(cdoidOfobjectA);
view.getResource(pathOfResourceA); << BANG !!!


Simon

Stephen McCants wrote:
> Hi Simon,
> I went back to reproduce the problem and I was unable to reproduce
> the error, even though I followed my own instructions. I'm not sure if
> there was something else that I didn't document that might have been
> causing the problem.
> Either way, you might want to take this with a grain of salt... I
> don't want to send you on a wild goose chase.
> Thanks for your help.
>
> --Stephen
>
> Simon McDuff wrote:
>> Can we have the stack trace ?
>>
>> Does the duplicate object is a Resource ?
>>
>> In the following bugzilla:
>> 248915: Resources fetched using CDOViewImpl.getResource(CDOID) not
>> added to ResourceSet
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=248915
>>
>> It happens also that the Resource is being added multiple times
>> resulting of a duplicate ID. It is fixed but you will need to upgrade.
>> (Warning: many others things changed in HEAD).
>> I think you could apply the patch v2 on that bug to fix your issue.
>>
>> If it is not the resource the problem... this will not fix your problem.
>>
>> Let me know if it is a resource and if it is possible the stack trace!
>>
>> Thank you!
>>
>>
>>
>>
>> "Stephen McCants" <stephenmccants@yahoo.com> wrote in message
>> news:48FE23A5.9080305@yahoo.com...
>>> Hi Simon,
>>> I'm using 2.0.0.200810082259. I have a deliverable at the end of the
>>> month and then we are planning to move to whatever the latest from
>>> HEAD is at that time. Thank you (and Eike as well) for the
>>> explanation of why #2 didn't work.
>>> If you need/want anything else from me, please let me know.
>>> Thanks for your help!
>>>
>>> --Stephen
>>
Previous Topic:Flattening a model to display in a table?
Next Topic:child tag failing because it IS in the same namespace.
Goto Forum:
  


Current Time: Fri Apr 26 10:15:30 GMT 2024

Powered by FUDForum. Page generated in 0.03667 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top