yasser777 / nettiers

Automatically exported from code.google.com/p/nettiers
0 stars 0 forks source link

Issue with Entity Tracking, Entity Factory, and 1-to-1 relationship #55

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Turn on entity tracking and entity factory
2. Find two entity types that have a one-to-one relationship.
3. Fill a T-List with an entity from the parent (primary table) side of the
relationship
4. Also get the related child that belongs to the entity 
5. Make another service call that will get the same parent record

What is the expected output? What do you see instead?
I expect the entity factory and tracker to recognize that the entity
already exists and handle the object references properly.  In other words
no matter how many service calls I make to get entity data from the
database I don't expect there to be problems.  The issue is that an
exception is thrown in the child entities copy method as it tries to add a
copy of its self to the existing copies hashtable but a copy already exists.  

What version of .netTiers and CodeSmith are you using?
.netTiers 2.3.0 Beta 1
CodeSmith 4.14

Please provide any additional information below.
I have included the stack trace below, replacing actual entity names with
parent and child consistent with the description above.  It appears that a
circular reference (using the term loosely) exists between the entities so
the parent keeps trying to copy the child and that causes the child to try
to copy the parent.  

   at System.Collections.Hashtable.Insert(Object key, Object nvalue,
Boolean add)
   at System.Collections.Hashtable.Add(Object key, Object value)
   at CCMS.Entities.ChildBase.Copy(IDictionary existingCopies)
   at CCMS.Entities.ChildBase.Clone(IDictionary existingCopies)
   at CCMS.Entities.ParentBase.MakeCopyOf(Object x, IDictionary existingCopies)
   at CCMS.Entities.ParentBase.Copy(IDictionary existingCopies)
   at CCMS.Entities.ParentBase.Clone(IDictionary existingCopies)
   at CCMS.Entities.ChildBase.MakeCopyOf(Object x, IDictionary existingCopies)
   at CCMS.Entities.ChildBase.Copy(IDictionary existingCopies)
   at CCMS.Entities.ChildBase.Clone()
   at CCMS.Entities.ParentBase.MakeCopyOf(Object x)
   at CCMS.Entities.ParentBase.ParentEntityData.Clone()
   at CCMS.Entities.ParentBase.AcceptChanges()
   at CCMS.Data.Bases.ParentProviderBaseCore.Fill(IDataReader reader,
TList`1 rows, Int32 start, Int32 pageLength)
   at
CCMS.Data.SqlClient.SqlParentProviderBase.GetByParentAssignmentId(TransactionMan
ager
transactionManager, Int32 _partyAssignmentId, Int32 start, Int32
pageLength, Int32& count)
   at CCMS.Services.ParentServiceBase.GetByParentAssignmentId(Int32
_parentAssignmentId, Int32 start, Int32 pageLength, Int32& totalCount)
   at CCMS.Services.ParentServiceBase.GetByParentAssignmentId(Int32
_parentAssignmentId)

Original issue reported on code.google.com by rhet...@gmail.com on 20 Jun 2008 at 4:02

GoogleCodeExporter commented 9 years ago
To follow up:  Entity Tracking and Entity Factory settings do not appear to be 
related to this issue.  

Original comment by rhet...@gmail.com on 20 Jun 2008 at 11:18

GoogleCodeExporter commented 9 years ago
It seems the issue is occuring when trying to save a new parent and child at 
the 
same time.  If I load an existing parent and child then modify them I can 
DeepSave 
without an issue.

Original comment by rhet...@gmail.com on 20 Jun 2008 at 11:43

GoogleCodeExporter commented 9 years ago
This happened to me too, and the issue does begin on: 
CCMS.Entities.ParentBase.AcceptChanges().

To put it simple, AcceptChanges is broken when the related object is loaded on 
the 
entity. To do a simple save (not deep), I had to null the property, save and 
then 
set the property again. Also note that entity tracking does affect this, as a 
simple 
get can come with the related object's property filled, and from then on you 
can't 
do a simple get (not deep).

Original comment by freddyri...@gmail.com on 2 Jul 2008 at 8:05

GoogleCodeExporter commented 9 years ago
More information can be found at the following forum thread
(http://community.codesmithtools.com/forums/p/8276/30939.aspx#30939)

What version of .netTiers and CodeSmith are you using?
2.2

duplicate issue (http://code.google.com/p/nettiers/issues/detail?id=17)

Original comment by bniemyjski on 8 Dec 2008 at 5:49

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 25 May 2009 at 3:30

GoogleCodeExporter commented 9 years ago
problem seems to still exist in .netTiers 2.3

Original comment by stafford...@gmail.com on 20 Jul 2009 at 11:45

GoogleCodeExporter commented 9 years ago
Hi - stumbled across this issue today and my obvious thought was: Well if the 
entity
already exists in the IDictionary, don't bother adding it again as it's already 
been
processed.

I put this after the if(existingCopies == null) statement at the beginning of
Copy(IDictionary existingCopies) in EntityInstanceBase.generated.cst:

else if (existingCopies.Contains(this))
{
   return (<%=className%>)existingCopies[this];
}

Works fine for me although maybe I'm potentially creating another bug? I don't 
know,
but like I say it works ok for me for now, will update if I get any problems.

Original comment by teppic.x...@gmail.com on 17 Sep 2009 at 2:50

GoogleCodeExporter commented 9 years ago
Hi - I have .netTiers 2.3.1. The problem still shows up while doing a copy.
I get this error:
   at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
   at System.Collections.Hashtable.Add(Object key, Object value)
   at MyProject.Entities.MyTableBase.Copy(IDictionary existingCopies)
   ..
   ..
Please help. 

Original comment by kissinge...@gmail.com on 8 Feb 2011 at 5:35

GoogleCodeExporter commented 9 years ago
I tried to update my current EntityProviderBaseCore.cst template with the patch 
provided here ->
http://community.codesmithtools.com/nettiers/f/30/p/5668/24286.aspx#24286

I am unable to find that spot to put those changes in this patch. Does this 
patch really work at all? 

Please help.

Original comment by kissinge...@gmail.com on 8 Feb 2011 at 7:46

GoogleCodeExporter commented 9 years ago
Please help with comment 8 or comment 9 posted by me. 
Also as mentioned in comment 7 by user 'teppic.x..', does it break anything or 
cause any problems if i go with that approach (in other words, use that elseif 
condition to check if the collection already exists).

Original comment by kissinge...@gmail.com on 8 Feb 2011 at 8:07

GoogleCodeExporter commented 9 years ago
Hello,

Does your scenario match the one defined above? If not how are you reproducing 
this issue. That patch is from 2007 and would need to be applied and updated to 
the current version.

I haven't reviewed this ticket before and would need to take a look at a sample 
to get up-to-speed.

Have you made the change discussed in comment 7? Did it resolved the issue? If 
it already exists in the collection than one would think it would be safe to 
apply the code in #7. But this is just an hypothesis with no debugging or time 
looking at this issue.

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 9 Feb 2011 at 7:38

GoogleCodeExporter commented 9 years ago
Hi,
I have not applied the code in #7 yet. I was concerned about breaking any 
existing code. 

Since you recommend applying it, i will go ahead and apply it. 

Will notify if i run into any problems.

Also, I wanted to share my problem scenario any way. Here's the situation:

I got a MyTransaction table that has a foreign key relationship with another 
table called MyLineItems. Hence when i save a MyTrans object having say 20-30 
count of MyLineItemsCollection, then I get this error after saving 
MyTransaction in the database. (ApplyChanges() method called). At this point it 
still need to save MyLineItems collection in to the database. It errors out 
with the below message.

  at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
   at System.Collections.Hashtable.Add(Object key, Object value)
   at MyProject.Entities.MyTableBase.Copy(IDictionary existingCopies)

Thanks a lot. 

Original comment by prachama...@gmail.com on 9 Feb 2011 at 9:16

GoogleCodeExporter commented 9 years ago
Hello,

Thanks a lot for that information. If you could apply that work around and keep 
us updated of the status of this issue in say a week that would be greatly 
appreciated!

Thanks
-Blake

Original comment by bniemyjski on 9 Feb 2011 at 10:16

GoogleCodeExporter commented 9 years ago
Hi , 

As of now, I didn't notice any issues pertaining to this change. Will keep you 
posted. Thanks.

Original comment by prachama...@gmail.com on 15 Feb 2011 at 11:10

GoogleCodeExporter commented 9 years ago
Hello,

Thanks for the update.

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 16 Feb 2011 at 4:45