inconsistency error one-many relation

12 posts, 1 answers
  1. codicezerouno
    codicezerouno avatar
    22 posts
    Member since:
    Feb 2009

    Posted 19 Apr 2010 Link to this post

    Hi guys,

    Consider to have two application that are connected to the same database, L2 cache enabled, consistency check enable, forwarding model with two class: order and orderline, order has a IList<OrderLine> property and OrderLine has the inverse field of type Order.

    1. In application A we add one OrderLine to Order; in Application B (already running) we got an inconsistency error on this one-many relation if we call commit (with no change made)

    2. In application A we remove one OrderLine from Order than we call scope.remove(orderline); in application B we got error when scope.commit (with no change made) that says "no row with OID 123".

    Any guidelines to fix this?

    thanks in advance.

    Stefano
  2. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 20 Apr 2010 Link to this post

    Hello Stefano Cadò,

    It seems that you have not turned on the L2 cache cluster synchronization. I would recommend you read the following help article where you should find the necessary information.

    Greetings,
    Zoran
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
  4. codicezerouno
    codicezerouno avatar
    22 posts
    Member since:
    Feb 2009

    Posted 20 Apr 2010 Link to this post

    Hi Zoran, thank you for your response.

    L2 cache cluster synchronization is on:

          <backendconfiguration id="mssqlConfiguration" backend="mssql">
            <l2CacheClusterTransport>MSMQ</l2CacheClusterTransport>
            <l2CacheClusterTransport.multicastaddr>224.1.1.1:666</l2CacheClusterTransport.multicastaddr>
            <logging.logEvents>normal</logging.logEvents>
            <performanceCounter>true</performanceCounter>
            <checkModelConsistencyOnCommit>True</checkModelConsistencyOnCommit>
            <mappingname>mssqlMapping</mappingname>
            <option.Multithreaded>True</option.Multithreaded>
          </backendconfiguration>

    I made other tests:
    I turned off L2 cache and I got inconsistency too on the same application. My win application is made of usercontrols; each user control has its own object scope. To invalidate the object scope cache (in each usercontrol) for refreshing shown data I call scope.Rollback (I have set TransactionProperties.AutomaticBegin = true).
    When the user change the data and save them, I use the user control scope to commit changes and in that moment I got "incosistency error".

    If I use a new object scope to make changes I don't get the error.
  5. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 21 Apr 2010 Link to this post

    Hello Stefano,

    so it is not an effect of L2 caching; good. Are you using managed inverse collections or normal inverse collections? With managed collections, the OrderLine side is maintained when you Add() or remove the OrderLine to the lines in the Order. When using non managed collections, you as user are responsible for correctly maintaining the relationship.
    What is the exact exception message?

    Kind regards,
    Thomas
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. codicezerouno
    codicezerouno avatar
    22 posts
    Member since:
    Feb 2009

    Posted 22 Apr 2010 Link to this post

    Hello Thomas,

    maybe the problem on l2 cache sync is due to the inconsistency problem, so I agree to solve the inconsistency problem before.

    the error message I have is:
    Telerik.OpenAccess.OpenAccessException: Inconsistent one-to-many: 'many' object [1431193282-3 Sigema.DAL.Cell] field Sigema.DAL.Cell.aggregatedArea is null
       in Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e)
       in Telerik.OpenAccess.RT.ExceptionWrapper.Throw()
       in OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.handleException(Exception x)
       in OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.internalCommit(Boolean phase)
       in OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.commit()
       in OpenAccessRuntime.DataObjects.SynchronizedPMProxy.commit()
       in Telerik.OpenAccess.RT.TransactionImpl.Commit()

    The strange thing is that I'm not changing the area-cell relation but I get the error on that.

    Consider that:
    The object scope used is always the same for the entire life of the usercontrol
    The usercontrol every 1 sec call scope.rollback to refresh data to be shown.
    MissionPark is called by a button click on the usercontrol.

    See the code I'm executing before committing is:
            public void MissionPark(DAL.Cell cell) 
            { 
     
                    var shuttle = cell.AggregationShuttle.SingleOrDefault(x => !x.HasActiveMissions); 
                    if (shuttle == nullthrow new ApplicationException("Nessuna navetta disponibile per l'operazione."); 
     
                    cell.Status = eCellStatus.MissionWaiting; 
     
                    var mission = new DAL.Mission(); 
     
                    mission.AggregatedCellSource = cell; 
                    //mission.AggregatedShuttle = shuttle; 
                    mission.Status = eMissionStatus.ReadyToPark; 
                    mission.CreatedOn = DateTime.Now; 
     
                    shuttle.AggregationMission.Add(mission); 
     
            } 

  7. codicezerouno
    codicezerouno avatar
    22 posts
    Member since:
    Feb 2009

    Posted 22 Apr 2010 Link to this post

    UPDATE, strange case:

    the error message I have is:
    Telerik.OpenAccess.OpenAccessException: Inconsistent one-to-many: 'many' object [1431193282-3 Sigema.DAL.Cell] field Sigema.DAL.Cell.aggregatedArea is null
       in Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e)
       in Telerik.OpenAccess.RT.ExceptionWrapper.Throw()
       in OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.handleException(Exception x)
       in OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.internalCommit(Boolean phase)
       in OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.commit()
       in OpenAccessRuntime.DataObjects.SynchronizedPMProxy.commit()
       in Telerik.OpenAccess.RT.TransactionImpl.Commit()

    Sigema.DAL.Cell.aggregatedArea is marked as "throw exception on null" in the model
    I have no error on commit if I remove the flag on "throw exception on null".



  8. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 24 Apr 2010 Link to this post

    Hello Stefano,

    the 'throw exception on null' setting allows for checking that the detail (many) instance is pointing to a master (one) instance. However, not always this is the desired behavior; think of the case where a detail can legally exist with no master. Therefore you can turn off the checking.  If you turn it off, the rows will correctly inserted/updated in the database.

    Kind regards,
    Thomas
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. codicezerouno
    codicezerouno avatar
    22 posts
    Member since:
    Feb 2009

    Posted 25 Apr 2010 Link to this post

    Hello Thomas,

    that's correct, and infact, if I want Cell.aggregatedArea to be not null I set tha flag to "true". In the database all records have not null in that field, in the context I get the error I never change that field, so I don't understand why it is null.
    I seems that the Area object has not been fetched (because never accessed), so aggregatedArea  is null and on commit, the 'check model consistency' throw exception.
    Do you think could be that?

    Best regards,
    Stefano
  10. Answer
    Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 26 Apr 2010 Link to this post

    Hi Stefano,

    yes, that it could be. Let me point out the managed vs. unmanaged behavior:
    (a) In managed collections, only Add/Remove should be used (on the master) and the runtime will automatically set the correct inverse reference and also handle an old collection.
    (b) In unmanaged collections, both side need to be brought into sync by the application. This involves setting the inverse as well as removing/adding to the collections. Please note, that you need to Remove() from the old collection as well in cases where a detail (many instance) is to be moved to a new master (one instance).
    The checks are the same for managed and unmanaged collections, but the code often looks much simpler when using managed collections.
    From the past descriptions I suspect that the oldMaster.Details.Remove(detail) call is missing; can you check that?

    Best wishes,
    Thomas
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  11. codicezerouno
    codicezerouno avatar
    22 posts
    Member since:
    Feb 2009

    Posted 27 Apr 2010 Link to this post

    Ok Thomas, that's more clear. Thank you.

    Considering to use case "a":

    - do not use 'throw null-exception' on the inverse field

    - do not set the inverse field on the code (it is managed by the runtime)

    - when adding: master.Details.Add(detail)
    it manages to remove detail from oldMaster
    ii fills the inverse field by itself
    if detail is "new" I don't need to call scope.Add(), right?

    - wnen removing: master.Details.Remove(detail)
    could I also use the following? detail.master.Details.Remove(detail)
    it clears the inverse field by itself
    if I need to delete the detail, after I need to call scope.Remove(detail)

    Any other note that can help?

    kind regards, Stefano.
  12. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 28 Apr 2010 Link to this post

    Hello Stefano,

    you are completely right about the settings! Add() and Remove() are then not symmetric in the sense, that Add() will make the instance persistent in the database, but Remove() will not remove the rows from the database... you will need to do that manually. But this is a very common problem in computing: how do you detect that something is no longer needed? 

    Kind regards,
    Thomas
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  13. codicezerouno
    codicezerouno avatar
    22 posts
    Member since:
    Feb 2009

    Posted 08 May 2010 Link to this post

    Hi Thomas,

    that's ok.

    Thank you and best regards.
Back to Top
DevCraft banner