HighLow Keygenerator with Firebird

7 posts, 0 answers
  1. Dennis
    Dennis avatar
    12 posts
    Member since:
    Oct 2012

    Posted 26 Mar 2013 Link to this post

    Hi,

    I'm using ORM 2013.1 and Firebird 2.5.2, and using code-only mapping.

    I set an Id with type long, and using KeyGenerator.HighLow with the code below.
    mappingConfiguration.HasProperty(objMap => objMap.Id).IsIdentity(KeyGenerator.HighLow);

    If I insert two objects and call SaveChanges, it will raise an exception on the second insert.
    Instance of 'class name here' with identity '60283631--1' already exists in the cache of the object scope.

    The database was able to create the voa_keygen table.  Even using a different KeyGenerator like Guid will not work, except for Autoinc which seems to be working.

    Any ideas how to solve this problem?
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 28 Mar 2013 Link to this post

    Hi Dennis,

    I was unable to reproduce the wrong behavior on my side. I have tested the problem against OpenAccess ORM Q1 2013. Please find the test application attached to my answer.

    All the best,
    Damyan Bogoev
    the Telerik team
    Free Webinar: OpenAccess Integration in Sitefinity. SIGN UP NOW.
  3. DevCraft banner
  4. Dennis
    Dennis avatar
    12 posts
    Member since:
    Oct 2012

    Posted 28 Mar 2013 Link to this post

    Hi Damyan,

    I checked your code and it is almost similar to mine so I was curious why your code is working and mine is not.  It turns out it has something to do with assigning the identify field "Id" to "-1".  In my constructor, I initialized all Id's to -1 and this is causing the problem.  I've modified your code and did the same and it causes the duplicate key exception.

    The reason I'm using the "-1" value is to check if my object has been added in the DB or not.

    1.  Will OA use negative numbers as identity?
    2.  What is the best way to check if my object has been persisted or not?  I can query the DB or add a new variable but maybe you have a better solution.

    Thanks!

    - Dennis
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 29 Mar 2013 Link to this post

    Hi Dennis,


    Actually this is expected behavior when a Highlow Key Generator is being used for a given persistence capable type. If you assign the identity member with a value different than 0 it will be used for persisting the corresponding entity to the database.

    You could use the following approach to obtain the state for the provided entity instance:

    ObjectState state = OpenAccessContext.PersistenceState.GetState(entity);


    Hope that helps.

    Regards,
    Damyan Bogoev
    the Telerik team
    Free Webinar: OpenAccess Integration in Sitefinity. SIGN UP NOW.
  6. Dennis
    Dennis avatar
    12 posts
    Member since:
    Oct 2012

    Posted 29 Mar 2013 Link to this post

    Hi Damyan,

    Thank you for the answer.  Got what I needed.

    One more thing, I mentioned I used 'long' as the type for my 'Id' but voa_keygen table uses 'int'.  Is there a way to change the data type from 'int' to 'long'?  or even use unsigned or negative numbers?

    Also, it is possible to have unused numbers in between grabs so what will happen if it cannot grab the range of number specified?  Ex.  'last_used_id' is already near the max value of 'int' and it cannot grab 10 more numbers.

    - Dennis
  7. Dennis
    Dennis avatar
    12 posts
    Member since:
    Oct 2012

    Posted 02 Apr 2013 Link to this post

    Hi, Anyone can help me with the voa_keygen on how to convert it to long?

    As for the last_used_id being all used up (Int32.MaxValue), I tested it and it will cause a DataStoreException.

    - Dennis
  8. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 03 Apr 2013 Link to this post

    Hello Dennis,

    I am afraid you are unable to specify the value column type. You could try migrate it manually directly on your Sql Server instance.

    I am sorry for the inconvenience caused.

    Kind regards,
    Damyan Bogoev
    the Telerik team 
Back to Top
DevCraft banner