This is a migrated thread and some comments may be shown as answers.

NoSuchObjectException - Set field to null?

7 Answers 131 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Wolfgang
Top achievements
Rank 1
Wolfgang asked on 28 Jan 2015, 01:13 PM
HI
following problem:
A field of a persistent type is pointing to another persistent object.
The persistent object is somehow no longer in object scope.
On accessing the property therefore an NoSuchObjectException occurs.

So my basic idea was - something bad had happened. At least log and clear up the data so that user can continue using the program.

But how could i cleanup the data? I would try to set the field to null.
      -> this.fieldName = null;   
throws a ... NoSuchObjectException - obviously the Object for the field is not available.

So how can i tell DataAccess that a NonExisting Object should be set to null?

Best regards
Wolfgang


sample code
[FieldAlias("fieldName")]
public SomePersistentType PropertyName
{
    get {...}
    set 
    {  
     
try
       {                 
             objectScope.Refresh(this.fieldName);
 
       }
       catch (Telerik.OpenAccess.Exceptions.NoSuchObjectException ex)
             
       {
                 
              this.fieldName = null;
                    
       }
...
    }
}

stack
NoSuchObjectException
No row for ... ('...') GenericOID@dc0de184 ... RowId=379e7a38-cc9e-4186-be7a-afd462792364
   bei Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e)
   bei OpenAccessRuntime.ExceptionWrapper.Throw()
   bei OpenAccessRuntime.DataObjects.PCStateMan.handleException(Exception x)
   bei OpenAccessRuntime.DataObjects.PCStateMan.setObjectFieldImp(PersistenceCapable _pc, FieldMetaData fmd, Object currentValue, Object newValue, Boolean rec)
   bei OpenAccessRuntime.DataObjects.PCStateMan.SetObjectField(PersistenceCapable _pc, Int32 field, Object currentValue, Object newValue)
   bei OpenAccessRuntime.DataObjects.SynchronizedStateManagerProxy.SetObjectField(PersistenceCapable pc, Int32 field, Object currentValue, Object newValue)

7 Answers, 1 is accepted

Sort by
0
Ady
Telerik team
answered on 30 Jan 2015, 02:23 PM
Hello Wolfgang,

 I guess you are using the classic approach to map your model. There is an attribute you can specify for a reference field which tells the runtime to not throw an exception if the object is not present but return null.

<extension key="null-if-not-found" value="true" />

Please add the above node under the <field> node for the required reference field.

Do get back in case you need further assistance.

Regards,
Ady
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
Wolfgang
Top achievements
Rank 1
answered on 09 Feb 2015, 12:45 PM
Hi Ady,

Sadly it has not worked as expected. 

Looking closer at the problem:
- Databound Grid  does a refresh of displayed data but a dispalyed object is deleted in the meantime.
- Grid accesses the object for some values (e.g.fieldName)
- objectScope.Refresh(this.fieldName) throws an error (and because of the error in get, we tried to set the value to null. Problem is that "this" does no longer exist for objectscope)

As the grid is bound to the data, we get sometimes an exception when an object is deleted. 

Regards
Wolfgang
0
Ady
Telerik team
answered on 12 Feb 2015, 10:48 AM
Hi Wolfgang,

 I have prepared a sample where I try to do something similar. I try and Refresh a deleted object and if it is not found I set the value to null. The 'null-if-not-found" attribute works if you try to access a reference field but is not obeyed for the Refresh call.

Do get back in case you need further assistance.

Regards,
Ady
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
Wolfgang
Top achievements
Rank 1
answered on 07 Apr 2015, 01:30 PM

Sadly It does not work as expected.

     objectScope.Refresh(this.fieldName);  throws a  NoSuchObjectException

 but with ssoem more information: the "this"-object seems to be gone, not the field object.

0
Ralph Waldenmaier
Telerik team
answered on 10 Apr 2015, 09:01 AM
Hi Wolfgang,
This is the expected behavior and the only way to deal with that is to set the reference to null in case such a exception is thrown, as already pointed out by Ady.
The problem also only exists in case you have no foreign keys in your database and in your case you also have a wrong information in the database since you are pointing to non existing records.
The correct way would be, when deleting the referenced object, to also clean up the references to this object. This would resolve the problem you experience.

I hope this information is helpful for you.
Do come back in case you need further assistance.

Regards,
Ralph Waldenmaier
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
Wolfgang
Top achievements
Rank 1
answered on 21 Apr 2015, 08:54 AM

Hi Ralph,

regarding foreign keys -> telerik ORM has created the DB from code. As Ady pointed out in other post sometimes not all references are created in DB (older stuff if pointing to each other). Seems in this case dependend data is also not deleted completly.

 And the problem is the cleanup of data . ATM for the task I completly forget telerik ORM. Has not worked to set it to null because it seems needs to read the thing first. So this is another task where i changed to do it in SQL directly in db (it is also quite easy to delete dependend objects there - using the information from telerik structure - and that is the sad thing. Within openaccess the deletion f dependend objects does not work, using just the structure information and crawling through database deletes it... ).

0
Ralph Waldenmaier
Telerik team
answered on 23 Apr 2015, 10:12 AM
Hi Wolfgang,
Yes, Telerik Data Access allows you to create references in the database without enforcing constraints. This can of course lead to the previously mentioned behavior.
Though it is supported, to delete dependent objects. Please see this link.
Although in the case where you want to delete the child, then you need to update the parent record as well, meaning, Data Access needs to know about this and therefore as you mentioned, it needs to load the data.
In your case the parent was not informed and therefore the dangling reference is generated.

In case you want to do some low level operations on the database, you might find our Low Level ADO API useful. Please see this link for more information.

I hope this information is helpful for you.
Feel free to ask in case you have any other question.

Regards,
Ralph Waldenmaier
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Data Access Free Edition
Asked by
Wolfgang
Top achievements
Rank 1
Answers by
Ady
Telerik team
Wolfgang
Top achievements
Rank 1
Ralph Waldenmaier
Telerik team
Share this question
or