CDO Duplicate ID problem or misuse? [message #424247] |
Tue, 21 October 2008 16:07 |
Stephen McCants 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 |
Simon Mc Duff 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 |
|
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
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Re: CDO Duplicate ID problem or misuse? [message #424264 is a reply to message #424247] |
Tue, 21 October 2008 17:56 |
Simon Mc Duff 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
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03667 seconds