Inheritance...

Why does it works when i used SingleTable and not when i used JoinedTable ?


It raise an exception EColumnMetadataNotFound with the message 'OPF Internal error: Column "UID" not found in table metadata "Person"'.


Here is a test case :

  {$DEFINE JoinStrategy}

  TBaseObject = class
  private
    [Column('UID',[TColumnProp.Required],39)]
    FUId : String;

    [Column('DTCREA', [TColumnProp.Required])]
    FDTCREA: TdateTime;

    [Column('DTMAJ', [TColumnProp.Required])]
    FDTMAJ: TdateTime;
    procedure SetDTCREA(const Value: TDateTime);

  public
    Constructor Create; virtual;
    property UID : String read FUID write FUID;
    property dtcrea : TDateTime read FDTCREA write SetDTCREA;
    property dtmaj : TDateTime read FDTMAJ write FDTMAJ;
  end;

  [Entity,Table('Person')]
  {$IFDEF JoinStrategy}
  [Inheritance(TInheritanceStrategy.JoinedTables)]
  {$ELSE}
  [Inheritance(TInheritanceStrategy.SingleTable)]
  [DiscriminatorColumn('CLASSNAME', TDiscriminatorType.dtString)]
  [DiscriminatorValue('PERSON')]
  {$ENDIF}
  [id('FUID',TIdGenerator.Uuid38)]
  TPerson = class(TBaseObject)
  private
    [Column('Titre', [],31)]
    FTitre: nullable<String>;

    [Column('Prenom', [TColumnProp.Required],31)]
    FPrenom: String;

    [Column('Nom', [TColumnProp.Required],31)]
    FNom: String;

    procedure SetNom(const Value: String);
    procedure SetPrenom(const Value: String);
    procedure SetTitre(const Value: nullable<String>);
  Public
    procedure GenerateTestData; Virtual;

    property Titre : nullable<String> Read FTitre write SetTitre;
    property Nom : String Read FNom write SetNom;
    property Prenom : String read FPrenom write SetPrenom;
  end;

  {$IFDEF JoinStrategy}
  [Entity, Table('Employee')]
  {$ELSE}
  [Entity]
  [DiscriminatorValue('EMPLOYEE')]
  {$ENDIF}
  TEmployee = class(TPerson)
  private
    [Column('Company', [],31)]
    FCompany: nullable<String>;
    procedure SetCompany(const Value: nullable<String>);
  Public
    procedure GenerateTestData; override;
    property Company : nullable<String> read FCompany write SetCompany;
  end;

You can't have Aurelius attributes declared in a non-entity class. It might work "by coincidence", not because it's by design. Your TBaseObject class must be an entity and persistent. That's why joined-tables doesn't work, because TBaseObject class must be persistent in its own table in database

Thank you for your quick reply