Is it possible to use a composite reference when one of the primary key fields is inherited?

4 posts, 0 answers
  1. Peter
    Peter avatar
    23 posts
    Member since:
    Sep 2008

    Posted 13 Oct 2011 Link to this post

    Hi

    I'm trying to set up a reference to a class with a composite key for which one of the primary fields is inherited.  One specific example:
    - Class Country_Audit has composite primary key with fields
       - int entityID, defined by itself, DB column is CountryID
       - int lockVersion, defined by superclass AuditLogEntry (in the same assembly), DB column is LockVersion
    - Class Country has a reference Country_Audit latestAuditLogEntry with the mapping:

    <field name="latestAuditLogEntry">
        <extension key="db-ref" value="entityID">
            <extension key="db-column-name" value="CountryID" />
        </extension>
        <extension key="db-ref" value="lockVersion">
            <extension key="db-column-name" value="LockVersion" />
        </extension>
    </field>

    When I run this, I get an exception:

    Telerik.OpenAccess.Exceptions.MetadataException : The field 'latestAuditLogEntry' of class 'MSW.MAPS.Testbed.Domain.Country' references a primary key field 'lockVersion' of class 'MSW.MAPS.Testbed.Domain.Country+Country_Audit' that could not be found. --> C:\Users\PeterW\AppData\Local\Temp\nunit20\ShadowCopyCache\8800_634540394140613784\Tests_1156102583\assembly\dl3\d8958bc2\f06f97d1_0089cc01\MSW.MAPS.Testbed.Domain.DLL:(resource)MSW.MAPS.Testbed.Domain.App.config:mapping-id=mssqlMapping/namespace[MSW.MAPS.Testbed.Domain]/class[Country]/field[latestAuditLogEntry]/db-ref="lockVersion"

    I know from replies to previous posts that OpenAccess has limitations with fields from superclasses (especially when they're in different assemblies); is this another case of that, or have I done something wrong?

    Thanks, Peter
  2. Ady
    Admin
    Ady avatar
    588 posts

    Posted 18 Oct 2011 Link to this post

    Hello Peter,

     I did refer  to a previous ticket from you in order to get the mentioned class setup. I did add a reference field to the class with a composite PK and was successfully able to create the database and obtain a new object scope i.e the metadata was successfully compiled. 
    I have attached the sample project used. Can you verify whether we are referring to the same setup or do you have something slighly different?

    Looking forward to resolving the issue with you soon.

    All the best,
    Ady
    the Telerik team

    Check out the latest stable build of Telerik OpenAccess ORM. Download it and benefit from our new Project Templates.

  3. DevCraft banner
  4. Peter
    Peter avatar
    23 posts
    Member since:
    Sep 2008

    Posted 20 Oct 2011 Link to this post

    Hi Ady

    Yes, this is related to that previous ticket, but a 'new' thing I'm trying to do (I didn't put the full details in because I thought what I'd put was enough, sorry about that).

    I've followed what you said, and made the db-ref point to the superclass field explicitly, ie:
    <extension key="db-ref" value="AuditLogEntry.lockVersion">...

    [Please can you update the documentation to say that this is how to reference a superclass field.]

    With that in place, I no longer get the MetadataException, but when trying to load an instance of the referencing class (Country in this test example), I get a SQLException (other fields removed from query to keep it simple):

    Telerik.OpenAccess.Exceptions.DataStoreException : Error executing query: Telerik.OpenAccess.RT.sql.SQLException: Invalid column name 'CountryID2'.
    Statement(s) could not be prepared.
       at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeQuery()
       at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeQuery()
       at OpenAccessRuntime.Relational.fetch.FetchResultImp.Execute()
    SQL:
    SELECT a.[CountryID] AS COL1, a.[LockVersion] AS COL2, a.[CountryID2] AS COL3, a.[LockVersion] AS COL4, ... FROM [Country] a WHERE a.[ThreeLetterCode] = ?

    I think the problem is that the CountryID database column is both the primary key of the Country class and part of the compound key referencing Country_Audit.  Checking the documentation, I now see that on the Mapping Fields to the same Columns page it says:
      "Using a reference in the primary key is not supported in the current release of OpenAccess."
    Is that the limitation I'm hitting here?  (I thought I was using a primary key as part of a reference, so didn't think that applied, but I now suspect I've misunderstood.)

    Assuming that is the case, I'm raise a support ticket to see what options there are to get around this.

    Best regards, Peter
  5. Ady
    Admin
    Ady avatar
    588 posts

    Posted 25 Oct 2011 Link to this post

    Hello Peter,

     I have provided a solution to your problem in you support ticket.

    Do get back in case you need further assistance.

    All the best,
    Ady
    the Telerik team

    NEW and UPDATED OpenAccess ORM Resources. Check them out!

Back to Top