CloneEntity plus join == problem in SyncFKFields

Posts   
 
    
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 25-Mar-2010 06:06:55   

Hi, running Postgres 8.4.x, 2.6 release version runtime libraries. I guess I don't know for sure that the problem is related to CloneEntity. That is an extension method based on other code here related to cloning. It also does resetting as new, and I use MarkSavedEntitiesAsFetched = true.

I'm guessing the issue is that new_re's collection of DeletedEntries from the join table is null? Anyway, thanks for giving it a look.


               //other Model changes
               Model.Deleted = false;
               //make a copy with all the updates
               ReportEntryEntity new_re = Model.CloneEntity();
               Model.CancelEdit(); //revert all changes
               Model.Deleted = true;
               Model.DeletingAnalyst = new_re.AnalystUserName;
               Model.AnalysisRecordTimestamp = DateTime.Now;

               using (DataAccessAdapter adapter = Create.Adapter())
               {
                  s_ILog.Debug("Saving");
                  adapter.SaveEntity(Model);
                  adapter.SaveEntity(new_re);
                  BucketJoinEntity joiner = new BucketJoinEntity();
                  joiner.DeletedIntermediate = Model;
                  joiner.Replacement = new_re;          //NullReference HERE
                  joiner.JoinReason = 0; //Manual
                  adapter.SaveEntity(joiner);
                  s_ILog.Debug("Saved");
               }

This throws at the commented line. Here is the stacktrace.

at SD.LLBLGen.Pro.ORMSupportClasses.EntityFields2.get_Item(String name) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.SyncFKFields(EntitySyncInfo1 syncInfo) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.SetEntitySyncInformation(String fieldName, IEntity2 relatedEntity, IEntityRelation relation) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.PerformSetupSyncRelatedEntity(IEntity2 relatedEntity, PropertyChangedEventHandler propertiesChangedHandler, String fieldName, IEntityRelation relation, Boolean connectToSaveEvent, String[] forfNames) at Zetec.Analysis.EntityClasses.BucketJoinEntity.SetupSyncReplacement(IEntity2 relatedEntity) at Zetec.Analysis.EntityClasses.BucketJoinEntity.SetRelatedEntity(IEntity2 relatedEntity, String fieldName) at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase21.PerformSetRelatedEntity(TEntity entity) at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore1.PerformAdd(T item) at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore1.Add(T item) at Zetec.Analysis.EntityClasses.ReportEntryEntity.SetRelatedEntity(IEntity2 relatedEntity, String fieldName) at Zetec.Analysis.EntityClasses.BucketJoinEntity.set_Replacement(ReportEntryEntity value) at ReportEditor.ViewModel.ReportEntryViewModel.FinishedEditing(Boolean save)

Here is a trimmed DDL



CREATE TABLE report_entries (
        report_entry_id SERIAL PRIMARY KEY,
        deleted boolean NOT NULL,
--snip
);

CREATE TABLE bucket_joins (
        deleted_id integer NOT NULL,
        report_entry_id integer NOT NULL,
        join_reason integer NOT NULL,
        PRIMARY KEY(deleted_id, report_entry_id)
);

ALTER TABLE bucket_joins ADD CONSTRAINT fk_report_join
        FOREIGN KEY (report_entry_id) REFERENCES report_entries (report_entry_id) ON DELETE CASCADE
;

ALTER TABLE bucket_joins ADD CONSTRAINT fk_deleted_join
        FOREIGN KEY (deleted_id) REFERENCES report_entries (report_entry_id) ON DELETE CASCADE
;

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 25-Mar-2010 10:50:16   

Which runtime library version (build numnber) are you using? (check Forum section guidelines).

Would you please post the code of CloneEntity()?

Another question:

                 joiner.Replacement = new_re;           //NullReference HERE
                 joiner.JoinReason = 0; //Manual

new_re is supposed to have a valid PK, since it was saved in an earlier step, right? Can you verify this by debugging?

And what is the second line of code for? (joiner.JoinReason = 0; //Manual)

tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 25-Mar-2010 15:03:22   

Version 2.6.9.1202

CloneEntity attached to this post: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=17120&StartAtMessage=0&#95909

Verified ReportEntrtyId is valid.

JoinReason is just a value of the join table entity.

Thanks

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 25-Mar-2010 21:04:44   

I didn't have a lot of luck trying to reproduce this for you.

Please could you

a) Upgrade to the latest version of the runtime libraries and try again b) If still experienceing the error, put together a small repro solution for us - code and dbscript only, no compiled dlls or runtime libs.

Thanks

Matt

tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 25-Mar-2010 22:11:44   

Got the latest version, same problem. Turned on Tracing, this is what I get:

//finishing adapter.SaveEntity(new_re); Method Exit: DataAccessAdapterBase.SaveEntity(4)

//about to do joiner.DeletedIntermediate = Model;
Method Enter: EntityBase2.SyncFKFields
Active Entity Description:
Entity: Zetec.Analysis.EntityClasses.BucketJoinEntity. ObjectID: d1eaed8b-26a4-46c7-9ae6-7fc986e5bd05
PrimaryKey field: DeletedId. Type: System.Int32. Value: <undefined value>
PrimaryKey field: ReportEntryId. Type: System.Int32. Value: <undefined value>
Data Supplying Entity Description:
Entity: Zetec.Analysis.EntityClasses.ReportEntryEntity. ObjectID: d1eaed8b-26a4-46c7-9ae6-7fc986e5bd05
PrimaryKey field: ReportEntryId. Type: System.Int32. Value: 1151
Syncing FK field DeletedId with PK field ReportEntryId Method Exit: EntityBase2.SyncFKFields

//about to do joiner.Replacement = new_re; Method Enter: CollectionCore.PerformAdd The thread 'Win32 Thread' (0xa7sunglasses has exited with code 0 (0x0). Entity to Add Description: Entity: Zetec.Analysis.EntityClasses.BucketJoinEntity. ObjectID: d1eaed8b-26a4-46c7-9ae6-7fc986e5bd05 PrimaryKey field: DeletedId. Type: System.Int32. Value: 1151 PrimaryKey field: ReportEntryId. Type: System.Int32. Value: <undefined value> Method Enter: EntityBase2.SyncFKFields Active Entity Description: Entity: Zetec.Analysis.EntityClasses.BucketJoinEntity. ObjectID: d1eaed8b-26a4-46c7-9ae6-7fc986e5bd05 PrimaryKey field: DeletedId. Type: System.Int32. Value: 1151 PrimaryKey field: ReportEntryId. Type: System.Int32. Value: <undefined value> Data Supplying Entity Description: Entity: Zetec.Analysis.EntityClasses.ReportEntryEntity. ObjectID: d1eaed8b-26a4-46c7-9ae6-7fc986e5bd05 PrimaryKey field: ReportEntryId. Type: System.Int32. Value: 1532 A first chance exception of type 'System.NullReferenceException' occurred in SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll

It appears it thinks new_re's ReportEntryId is invalid. Would I be better off setting joiner.ReportEntryId instead of joiner.Replacement? As I write this, I think that perhaps my naming isn't terribly helpful simple_smile .

tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 25-Mar-2010 22:33:09   

Well, no. Just setting the FK doesn't cause LLBLGen to deal with all my FK fields, but the PK was available, and upon refreshing from the database, my join was operating properly.

changed code to this:


                  BucketJoinEntity joiner = new BucketJoinEntity();
                  joiner.DeletedIntermediate = Model;
                  joiner.ReportEntryId = new_re.ReportEntryId;
                  joiner.Replacement = new_re;

And now I see this

Method Exit: DataAccessAdapterBase.SaveEntity(4)
Method Enter: EntityBase2.SyncFKFields
Active Entity Description:
Entity: Zetec.Analysis.EntityClasses.BucketJoinEntity. ObjectID: 01327b6f-f836-4bd6-9986-d934dc3a0076
PrimaryKey field: DeletedId. Type: System.Int32. Value: <undefined value>
PrimaryKey field: ReportEntryId. Type: System.Int32. Value: <undefined value>
Data Supplying Entity Description:
Entity: Zetec.Analysis.EntityClasses.ReportEntryEntity. ObjectID: 01327b6f-f836-4bd6-9986-d934dc3a0076
PrimaryKey field: ReportEntryId. Type: System.Int32. Value: 1532

Syncing FK field DeletedId with PK field ReportEntryId Method Exit: EntityBase2.SyncFKFields Method Enter: CollectionCore.PerformAdd Entity to Add Description: Entity: Zetec.Analysis.EntityClasses.BucketJoinEntity. ObjectID: 01327b6f-f836-4bd6-9986-d934dc3a0076 PrimaryKey field: DeletedId. Type: System.Int32. Value: 1532 PrimaryKey field: ReportEntryId. Type: System.Int32. Value: 1535 Method Enter: EntityBase2.SyncFKFields Active Entity Description: Entity: Zetec.Analysis.EntityClasses.BucketJoinEntity. ObjectID: 01327b6f-f836-4bd6-9986-d934dc3a0076 PrimaryKey field: DeletedId. Type: System.Int32. Value: 1532 PrimaryKey field: ReportEntryId. Type: System.Int32. Value: 1535 Data Supplying Entity Description: Entity: Zetec.Analysis.EntityClasses.ReportEntryEntity. ObjectID: 01327b6f-f836-4bd6-9986-d934dc3a0076 PrimaryKey field: ReportEntryId. Type: System.Int32. Value: 1535 A first chance exception of type 'System.NullReferenceException' occurred in SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll

Are all of the object id's supposed to be the same?

tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 25-Mar-2010 22:38:51   

Well, I'm up against a release, so I'll go with this hack for now


                  adapter.SaveEntity(new_re);
                  int id = new_re.ReportEntryId;
                  new_re = new ReportEntryEntity(id);
                  adapter.FetchEntity(new_re);
                  BucketJoinEntity joiner = new BucketJoinEntity();
                  joiner.DeletedIntermediate = Model;
                  joiner.Replacement = new_re;

Hopefully I'll have time to come back to this and make a test app.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Mar-2010 03:41:59   

Weird,

Please try setting the property from the other side:

new_re.BucketJoins.Add(joiner);

Anyway, we will wait for your repro solution to take a closer look. I will close this thread for the moment, please just post a message to reopen it.

David Elizondo | LLBLGen Support Team