Menu

Object creation in db with string primary key

Phil
2006-08-21
2013-04-22
  • Phil

    Phil - 2006-08-21

    Hi,
    I made futher test on DomainObject and I get this problem.
    With my db access class I try to create Patient. Patient has a string as primary key :
      <ClassDescriptor ClassName="com.diagast.testdbmapping.Patient" TableName="PATIENT">
        <PrimaryKeyDescriptor IsAutoIncremented="false">
          <FieldDescriptor Id="PATIENT1" FieldName="_primaryKey" IsDeclaredInBaseClass="true" DbType="AnsiString" ColumnName="ID" Length="100" />
        </PrimaryKeyDescriptor>
        <FieldDescriptor Id="PATIENT2" FieldName="_name" PropertyName="Name" DbType="AnsiString" ColumnName="NAME" Length="60" />
        <FieldDescriptor Id="PATIENT3" FieldName="_firstname" PropertyName="Firstname" DbType="AnsiString" ColumnName="FIRSTNAME" Length="60" />
        <FieldDescriptor Id="PATIENT4" FieldName="_birthdate" PropertyName="Birthdate" DbType="DateTime" ColumnName="BIRTHDATE" />
      </ClassDescriptor>

    I use my dbaccess class like this :
    // always return null because the object is never created.
                Patient pat1 = (Patient)dbaccess.FindObjectInDBWithPrimaryKey<Patient>("name_pat1" + "first_pat1");
    //create the patient. No created in db ???
                pat1 = new Patient("name_pat1", "first_pat1", new DateTime());
                pat1 = (Patient)dbaccess.CreateObjectInDB<Patient>(pat1);
               
                //get patient 1
    // return the patient even if it's not created in db. I think It come from the cache.
                pat1 = (Patient)dbaccess.FindObjectInDBWithPrimaryKey<Patient>("name_pat1" + "first_pat1");

    The CreateObjectInDB never create the patient. I have other mapped object like Demand that have int primarykey and it works. But for the patient they are never created. The FindObjectInDBWithPrimaryKey find the patient but not in the DB.

    Have you any idea ?

    Regards

    Philippe Delrieu

     
    • Richard Beauchamp

      Hi Philippe,

      Let me write some unit tests that involve a string primary key and I'll get back to you. All of our current unit tests utilize an int primary key...

       
    • Steven Archibald

      Hmm... You might as well test w/ GUID's as a primary key as well.

       
    • Phil

      Phil - 2006-09-28

      Hi Richard,
      I don't understand your remarq.
      Did you find anything ?

      regards

      Philippe

       
      • Richard Beauchamp

        No I haven't found anything yet. If you send me your test project on this one also, it will make it easier for me to reproduce... Thanks Philippe.

         
    • Phil

      Phil - 2006-09-28

      Hi Richard,
      the problem can be seen in the same project as the other post (I resend you the project).
      At the beginning of createDBObject method (ObjectFactory.cs line 102),
      I create a patient and store it in db.
      After the creation, I look the table with a query tool, no patient is created.
      After I query the database, the patient is found but it isn't in db.

      regards

      Philippe Delrieu

       

Log in to post a comment.