NoSuchObjectException - Set field to null?

8 posts, 0 answers
  1. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 28 Jan 2015 Link to this post

    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)
  2. Ady
    Admin
    Ady avatar
    588 posts

    Posted 30 Jan 2015 Link to this post

    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.
     
  3. DevCraft banner
  4. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 09 Feb 2015 in reply to Ady Link to this post

    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
  5. Ady
    Admin
    Ady avatar
    588 posts

    Posted 12 Feb 2015 Link to this post

    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.
     
  6. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 07 Apr 2015 in reply to Ady Link to this post

    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.

  7. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 10 Apr 2015 Link to this post

    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.
     
  8. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 21 Apr 2015 in reply to Ralph Waldenmaier Link to this post

    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... ).

  9. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 23 Apr 2015 Link to this post

    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.
     
Back to Top
DevCraft banner