Duplicate column name

I am using the newest version of Aurelius.
Some time ago, I defined a table definition very similary to the one, I try to create now. And the "old" one has created successfully.
Today I try to create the following one:

// ******************************
// TMyClients
// ******************************
[Entity]
[Id('FId', TIdGenerator.None)]
[Table('Clients')]
[UniqueKey('MandantID, MacAddress')]
TMyClients = class
  private
  [Column('Id', [TColumnProp.Required], StringLenUID)]
  FId: String;

  [Column('MandantID', [], StringLenMandantID)]
  FMandantID: Nullable<String>;

  [Column('MacAdresse', [TColumnProp.Required], StringLenMacAdresse)]
  FMacAdresse: String;

  [Column('IsActive')]
  FIsActive: Boolean;

  [Column('LastUsed', [TColumnProp.Required])]
  FLastUsed: TDateTime;

  [Version]
  FVersion: Integer;

  public
  property Id: String
      read FId
     write FId;

  property MandantID: Nullable<String>
      read FMandantID
     write FMandantID;

  property MacAdresse: String
      read FMacAdresse
     write FMacAdresse;

  property IsActive: Boolean
      read FIsActive
     write FIsActive;

  property LastUsed: TDateTime
      read FLastUsed
     write FLastUsed;

  property Version: Integer
      read FVersion;
end; //of class

And now, I am getting the following error message, when the application is started (compiling finished successfully):

Error: duplicate column name: MandantId

CREATE TABLE Clients (
  Id TEXT NOT NULL,
  MandantID TEXT,
  MacAdresse TEXT NOT NULL,
  IsActive TEXT,
  LastUsed REAL NOT NULL,
  MandantId TEXT NOT NULL,
  CONSTRAINT PK_Clients PRIMARY KEY (Id),
  CONSTRAINT FK_Clients_Mandants_MandantID FOREIGN KEY (MandantID) REFERENCES Mandants (MandantID),
  CONSTRAINT UK_A222CAE9_Clients UNIQUE (MandantID, MacAdresse))

Deleting the database and recreate it by code (ORM) ends with a problem on the old table, which had no creation problem in the past.
Why does this happen? Please help

Please provide the full mapping for both TMyClients and Mandats classes.

I think I have located the problem.
In the Mandants class I defined a ManyValueAssociation to the Clients.
The Mandant Class has also a column "MandantID" which is used as ID

// ******************************
// TMyMandants
// ******************************
[Entity]
[Id('FMandantID', TIdGenerator.None)]
[Table('Mandants')]
TMyMandants = class
private
  [ManyValuedAssociation([TAssociationProp.Lazy], [TCascadeType.RemoveOrphan] + 
  [TCascadeType.Evict])]
  [ForeignJoinColumn('MandantId', [])]
  FClients: Aurelius.Types.Proxy.Proxy<System.Generics.Collections.TList<TMyClients>>;

  [Column('MandantID', [TColumnProp.Required], StringLenMandantID)]
  FMandantID: String;

  [Column('MandantName', [TColumnProp.Unique], StringLenMandantName)]
  FMandantName: String;

  [Version]
  FVersion: Integer;

  function GetClients: System.Generics.Collections.TList<TMyClients>;

public
  constructor Create; virtual;
  destructor  Destroy; override;

  property Clients: System.Generics.Collections.TList<TMyClients>
      read GetClients;

  property MandantId: String
      read FMandantID
     write FMandantID;

  property MandantName: String
      read FMandantName
     write FMandantName;

  property Version: Integer
     read  FVersion;
end;//of class

After removing the ManyValueAssociation in Mandants table, the problem is gone.

So, when the Create table SQL statment is build, it should check deeper, if an column with the same name is already there with the same column definition. If yes, it should not add the column used by the Association (if both are "MandantId TEXT" - in my code the association was declared as "required" to the column, so the "NOT NULL" addition was there).

Also it would be nice, if the mapping problem is being shown on startup (debug mode) - if possible.

For now Aurelius mapper doesn't check for duplicated column names until it actually uses it. To really explain what happened I'd have to see the full original mapping. But indeed, if you mapped two columns with same name, it will complain.

From the information you sent via e-mail, the problem is your mapping is indeed messy:

 [Table('Clients')]

 TBevCrateTrackerClients = class

...

   [Column('Id', [TColumnProp.Required], StringLenUID)]

   FId: String;…

...

   [Column('MandantId', [], StringLenMandantID)]

   FMandantID: Nullable<String>;

…

   [Association([TAssociationProp.Lazy], [])]

   [JoinColumn('ID', [])]

   FMandant: Proxy<TBevCrateTrackerMandants>;

 [Table('Mandants')]

 TBevCrateTrackerMandants = class

…

   [ManyValuedAssociation([TAssociationProp.Lazy], [TCascadeType.RemoveOrphan] + [TCascadeType.Evict])]

   [ForeignJoinColumn('MandantId', [])]

   FClients: Aurelius.Types.Proxy.Proxy<System.Generics.Collections.TList<TBevCrateTrackerClients>>;

You have two columns “ID” mapped in table “Clients” (from fields FId and FMandant).

You have two columns “MantandID” mapped in table “Clients” (from fields TBevCrateTrackerClients.FMandantID and TBevCrateTrackerMandants.FClients.

Here is how your mapping should look like:

 [Table('Clients')]

 TBevCrateTrackerClients = class

...

   [Column('Id', [TColumnProp.Required], StringLenUID)]

   FId: String;…

…

   [Association([TAssociationProp.Lazy], [])]

   [JoinColumn(“MandantId', [], StringLenMandantID)]

   FMandant: Proxy<TBevCrateTrackerMandants>;

 [Table('Mandants')]

 TBevCrateTrackerMandants = class

…

   [ManyValuedAssociation([TAssociationProp.Lazy], [TCascadeType.RemoveOrphan] + [TCascadeType.Evict], 'FMandant')]

   FClients: Aurelius.Types.Proxy.Proxy<System.Generics.Collections.TList<TBevCrateTrackerClients>>;

Hello Andreas,

The problem is your mapping is indeed messy:

 [Table('Clients')]

 TBevCrateTrackerClients = class

...

   [Column('Id', [TColumnProp.Required], StringLenUID)]

   FId: String;…

...

   [Column('MandantId', [], StringLenMandantID)]

   FMandantID: Nullable<String>;

…

   [Association([TAssociationProp.Lazy], [])]

   [JoinColumn('ID', [])]

   FMandant: Proxy<TBevCrateTrackerMandants>;

 [Table('Mandants')]

 TBevCrateTrackerMandants = class

…

   [ManyValuedAssociation([TAssociationProp.Lazy], [TCascadeType.RemoveOrphan] + [TCascadeType.Evict])]

   [ForeignJoinColumn('MandantId', [])]

   FClients: Aurelius.Types.Proxy.Proxy<System.Generics.Collections.TList<TBevCrateTrackerClients>>;