class with AbstractEntity the error is happening:EEntityTypeMappingFailed: Error mapping entity type Jetro.fat.LanctoMdl.TLanctoParcelaFatBsc: Invalid MappedBy parameter in ManyValuedAssociation on TLanctoParcelaFatBsc.FListaLanctoSangriaDocFat member

I have a class that I'm using AbstractEntity and
I have a list in it and the following error appears when I initialize the application: EEntityTypeMappingFailed: Error mapping entity type Jetro.fat.LanctoMdl.TLanctoParcelaFatBsc: Invalid MappedBy parameter in ManyValuedAssociation on TLanctoParcelaFatBsc.FListaLanctoSangriaDocFat member (EInvalidMappedByReference)

in the documentation it says that it can be used with association.

[AbstractEntity]
[Table('fat_lancto_parcela')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
[Filter('StaAtivo')]

TLanctoParcelaFatBsc = class(TModeloBsc)
.
.
.
[ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAllRemoveOrphan, 'FLanctoParcelaFat')]
FListaLanctoSangriaDocFat: Proxy<TList>;

What is the full mapping of both classes involved? In your code I only see Proxy<TList> which is obviously a wrong type.

{ TModeloBsc }

[AbstractEntity]
[FilterDef('StaAtivo', '{Sta} = 1')]
[FilterDef('StaNaoExcluido', '{Sta} <> 2')]

TModeloBsc = class abstract
private
FParentVo: TObject;

function GetIdFront: string;

protected
function FmtIdDg: string;
protected
(*
adicionar no uses
XData.Model.Attributes,

adicionar no public da classe que tera a propriedade disponivel
[XDataProperty]
property IdFront;

*)
property IdFront: string read GetIdFront;
public
constructor Create; overload; virtual;
constructor Create(pOwner: TObject); overload;

class function MsgNaoInformado(pArtigo, pCampo: string): string; virtual;

function  ParentVo: TObject; overload;
function  ParentVo<TClassCast: class>: TClassCast; overload;
procedure ParentVo(Value: TObject); overload;

end;

{ TLanctoParcelaFat }

[Entity]
[Model('Default')]
[Model('DDL')]
[Table('fat_lancto_parcela')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
[Sequence('fat_lancto_parcela_id_seq')]
[Filter('StaAtivo')]

TLanctoParcelaFat = class(TModeloBsc)
private
[Column('id', [TColumnProp.Required])]
FId: int64;

[Column('sta', [TColumnProp.Required])]
FSta: TStatus;

[Association([TAssociationProp.Lazy, TAssociationProp.Required])]
[ForeignKey('fk_fat_lancto_parcela_1')]
[JoinColumn('fat_lancto_id', [TColumnProp.Required])]
FLanctoFat: Proxy<TLanctoFat>;

[Association([TAssociationProp.Lazy, TAssociationProp.Required])]
[ForeignKey('fk_fat_lancto_parcela_11')]
[JoinColumn('adm_tipo_forma_pag_id', [TColumnProp.Required])]
FTipoFormaPagAdm: Proxy<TTipoFormaPagAdm>;

[Association([TAssociationProp.Lazy, TAssociationProp.Required])]
[ForeignKey('fk_fat_lancto_parcela_2')]
[JoinColumn('adm_forma_pag_id', [TColumnProp.Required])]
FFormaPagAdm: Proxy<TFormaPagAdm>;

[Association([TAssociationProp.Lazy])]
[ForeignKey('fk_fat_lancto_parcela_5')]
[JoinColumn('com_plano_pag_id', [])]
FPlanoPagCom: Proxy<TPlanoPagCom>;

[Column('documento', [], 20)]
FDocumento: Nullable<string>;

[Column('data_vencimento')]
FDataVencimento: Nullable<TDateTime>;

[Column('valor_troco', [], 14, 2)]
FValorTroco: Nullable<currency>;

[Column('valor_operacao', [TColumnProp.Required], 14, 2)]
FValorOperacao: currency;

[Column('total_bruto', [TColumnProp.Required], 14, 2)]
FTotalBruto: currency;

[Column('perc_desconto', [TColumnProp.Required], 6, 2)]
FPercDesconto: currency;

[Column('total_liquido', [TColumnProp.Required], 14, 2)]
FTotalLiquido: currency;

[Association([TAssociationProp.Lazy])]
[ForeignKey('fk_fat_lancto_parcela_3')]
[JoinColumn('fin_banco_conta_id')]
FBancoContaFin: Proxy<TBancoContaFin>;

[Association([TAssociationProp.Lazy])]
[ForeignKey('fk_fat_lancto_parcela_4')]
[JoinColumn('fin_banco_cheque_id')]
FChequeBancoFin: Proxy<TBancoFin>;

[Column('agencia_cheque', [], 6)]
FChequeAgencia: Nullable<string>;

[Column('conta_corrente_cheque', [], 20)]
FChequeContaCorrente: Nullable<string>;

[Column('numero_cheque', [], 20)]
FChequeNumero: Nullable<string>;

[Column('descricao', [], 60)]
FDescricao: Nullable<string>;

[Column('detalhe', [], 60)]
FDetalhe: Nullable<string>;

[Column('cartao_credito_debito', [], 1)]
FCartaoCreditoDebito: Nullable<string>;

[Column('cartao_vezes')]
FCartaoVezes: Nullable<integer>;

[Column('cartao_nsu')]
FCartaoNsu: Nullable<int64>;

[Column('cartao_autorizacao', [], 20)]
FCartaoAutorizacao: Nullable<string>;

[Column('cartao_cvad', [], 20)]
FCartaoCvad: Nullable<string>;

[Column('seq_forma_pag')]
FSeqFormaPag: Nullable<integer>;

FCartaoCnpjCredVo: Int64;

[Association([TAssociationProp.Lazy])]
[ForeignKey('fk_fat_lancto_parcela_6')]
[JoinColumn('fat_lancto_plano_id')]
FLanctoPlanoFat: Proxy<TLanctoPlanoFat>;

[Column('id_pagto_gateway', [], 100)]
FPagtoGatewayId: Nullable<string>;

[ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAllRemoveOrphan, 'FLanctoParcelaFat')]
FListaLanctoSangriaDocFat: Proxy<TList<TLanctoSangriaDocFat>>;

function GetFormaPagAdm: TFormaPagAdm;
function GetPlanoPagCom: TPlanoPagCom;
function GetLanctoFat: TLanctoFat;
function GetLanctoPlanoFat: TLanctoPlanoFat;
procedure SetLanctoPlanoFat(const Value: TLanctoPlanoFat);
function GetTipoFormaPagAdm: TTipoFormaPagAdm;
procedure SetFormaPagAdm(const Value: TFormaPagAdm);
procedure SetPlanoPagCom(const Value: TPlanoPagCom);
procedure SetLanctoFat(const Value: TLanctoFat);
procedure SetTipoFormaPagAdm(const Value: TTipoFormaPagAdm);
function GetBancoContaFin: TBancoContaFin;
procedure SetBancoContaFin(const Value: TBancoContaFin);
function GetChequeBancoFin: TBancoFin;
procedure SetChequeBancoFin(const Value: TBancoFin);
function GetListaLanctoSangriaDocFat: TList<TLanctoSangriaDocFat>;
function GetValorDesconto: currency;

public
constructor Create; override;
destructor Destroy; override;

procedure SetTipoFormaPagAdmDefault;
procedure SumProps(pLanctoParcelaFat: TLanctoParcelaFat);

public
property Id: int64 read FId write FId;
property Sta: TStatus read FSta write FSta;
property LanctoFat: TLanctoFat read GetLanctoFat write SetLanctoFat;
property TipoFormaPagAdm: TTipoFormaPagAdm read GetTipoFormaPagAdm write SetTipoFormaPagAdm;
property FormaPagAdm: TFormaPagAdm read GetFormaPagAdm write SetFormaPagAdm;
property PlanoPagCom: TPlanoPagCom read GetPlanoPagCom write SetPlanoPagCom;
property Documento: Nullable read FDocumento write FDocumento;
property DataVencimento: Nullable read FDataVencimento write FDataVencimento;
property TotalBruto: currency read FTotalBruto write FTotalBruto;
property PercDesconto: currency read FPercDesconto write FPercDesconto;
property TotalLiquido: currency read FTotalLiquido write FTotalLiquido;
property ValorTroco: Nullable read FValorTroco write FValorTroco;
property ValorOperacao: currency read FValorOperacao write FValorOperacao;
property BancoContaFin: TBancoContaFin read GetBancoContaFin write SetBancoContaFin;
property ChequeBancoFin: TBancoFin read GetChequeBancoFin write SetChequeBancoFin;
property ChequeAgencia: Nullable read FChequeAgencia write FChequeAgencia;
property ChequeContaCorrente: Nullable read FChequeContaCorrente write FChequeContaCorrente;
property ChequeNumero: Nullable read FChequeNumero write FChequeNumero;
property Descricao: Nullable read FDescricao write FDescricao;
property Detalhe: Nullable read FDetalhe write FDetalhe;
property CartaoCreditoDebito: Nullable read FCartaoCreditoDebito write FCartaoCreditoDebito;
property CartaoVezes: Nullable read FCartaoVezes write FCartaoVezes;
property CartaoNsu: Nullable read FCartaoNsu write FCartaoNsu;
property CartaoAutorizacao: Nullable read FCartaoAutorizacao write FCartaoAutorizacao;
property CartaoCvad: Nullable read FCartaoCvad write FCartaoCvad;
property SeqFormaPag: Nullable read FSeqFormaPag write FSeqFormaPag;
property CartaoCnpjCredVo: Int64 read FCartaoCnpjCredVo write FCartaoCnpjCredVo;
property PagtoGatewayId: Nullable read FPagtoGatewayId write FPagtoGatewayId;
property LanctoPlanoFat: TLanctoPlanoFat read GetLanctoPlanoFat write SetLanctoPlanoFat;

property ListaLanctoSangriaDocFat: TList<TLanctoSangriaDocFat> read GetListaLanctoSangriaDocFat;
[XDataProperty]
property IdFront;

public
{ property backend }
property ValorDesconto: currency read GetValorDesconto;
end;

{ TLanctoSangriaDocFat }

[Entity]
[Model('Default')]
[Model('DDL')]
[Table('fat_lancto_sangria_doc')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
[Sequence('fat_lancto_sangria_doc_id_seq')]
[Filter('StaAtivo')]

TLanctoSangriaDocFat = class(TModeloBsc)
private
[Column('id', [TColumnProp.Required])]
FId: int64;

[Column('sta', [TColumnProp.Required])]
FSta: TStatus;

[Association([TAssociationProp.Lazy, TAssociationProp.Required])]
[ForeignKey('fk_fat_lancto_sangria_doc_2')]
[JoinColumn('fat_lancto_sangria_id', [TColumnProp.Required])]
FLanctoSangriaFat: Proxy<TLanctoSangriaFat>;

[Association([TAssociationProp.Lazy, TAssociationProp.Required])]
[ForeignKey('fk_fat_lancto_sangria_doc_1')]
[JoinColumn('fat_lancto_parcela_id', [TColumnProp.Required])]
FLanctoParcelaFat: Proxy<TLanctoParcelaFat>;

function GetLanctoSangriaFat: TLanctoSangriaFat;
function GetLanctoParcelaFat: TLanctoParcelaFat;
procedure SetLanctoSangriaFat(const Value: TLanctoSangriaFat);
procedure SetLanctoParcelaFat(const Value: TLanctoParcelaFat);

public
property Id: int64 read FId write FId;
property Sta: TStatus read FSta write FSta;
property LanctoSangriaFat: TLanctoSangriaFat read GetLanctoSangriaFat write SetLanctoSangriaFat;
property LanctoParcelaFat: TLanctoParcelaFat read GetLanctoParcelaFat write SetLanctoParcelaFat;
[XDataProperty]
property IdFront;
end;

Your post is very confusing when it comes to formatting. But I couldn't find any classe named TLanctoParcelaFatBsc.

What I see though is that in class TLanctoSangriaDocFat you have a field:

FLanctoParcelaFat: Proxy<TLanctoParcelaFat>;

Thus, you can only create a ManyValuedAssociation that lists TLanctoSangridDocFat in class TLanctoParcelaFat.

mapping in a simpler way.
the intention of putting the list in the TLanctoFatBsc because it will be common to other classes that will inherit from the TLanctoFatBsc

[AbstractEntity]
[Model('Default')]
[Table('fat_lancto_parcela')]
[Id('FId', TIdGenerator.IdentityOrSequence)]

TLanctoParcelaFatBsc = class
private
[Column('id', [TColumnProp.Required])]
FId: int64;

[Association([TAssociationProp.Lazy, TAssociationProp.Required])]
[JoinColumn('fat_lancto_id', [TColumnProp.Required])]
FLanctoFat: Proxy<TLanctoFat>;

function GetLanctoFat: TLanctoFat;
procedure SetLanctoFat(const Value: TLanctoFat);

public
property Id: int64 read FId write FId;
property LanctoFat: TLanctoFat read GetLanctoFat write SetLanctoFat;
end;

[Entity]
[Model('Default')]
[Table('fat_lancto_parcela')]
[Sequence('fat_lancto_parcela_id_seq')]

TLanctoParcelaFat = class(TLanctoParcelaFatBsc)

end;

[AbstractEntity]
[Model('Default')]
[Table('fat_lancto')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
TLanctoFatBsc = class
private
[Column('id', [TColumnProp.Required])]
FId: int64;

[ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAllRemoveOrphan, 'FLanctoFat')]
FListaLanctoParcelaFat: Proxy<TList<TLanctoParcelaFat>>;

function GetListaLanctoParcelaFat: TList<TLanctoParcelaFat>;

public
constructor Create;
destructor Destroy; override;

property Id: int64 read FId write FId;
property ListaLanctoParcelaFat: TList<TLanctoParcelaFat> read GetListaLanctoParcelaFat;

end;

[Entity]
[Model('Default')]
[Table('fat_lancto')]
[Sequence('fat_lancto_id_seq')]

TLanctoFat = class(TLanctoFatBsc)

end;

Yes, but then TLanctoParcelaFatBsc has an association to TLanctoFat, not TLanctoFatBasc. Thus it's not possible.

but TLanctoParcelaFat does not inherit from TLanctoParcelaFatBsc. if you put FListaLanctoParcelaFat in TLanctoFat it works. for me what is missing is the routine that makes the validation also see the fields of the ancestor.

This is very confusing, including the name and the inheritance. Can you please provide a small project with the minimal classes needed to reproduce the issue?

AbstractEntity.zip (53.8 KB)
Attached is a project that simulates the situation

Ok, as I mentioned before, what you want to achieve is not possible. You have the following class hierarchy:

  TLanctoParcelaFatBsc = class;
  TLanctoParcelaFat = class(TLanctoParcelaFatBsc)

  TLanctoFatBsc = class;
  TLanctoFat = class(TLanctoFatBsc)

Here is your ManyValuedAssociaiton declaration:

  TLanctoFatBsc = class
  private
    [ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAllRemoveOrphan, 'FLanctoFat')]
    FListaLanctoParcelaFat: Proxy<TList<TLanctoParcelaFat>>;

So it declares the other side of the association as the FLanctoFat field. However, the FLanctoFat field is declared as:

    [Association([TAssociationProp.Lazy, TAssociationProp.Required])]
    [JoinColumn('fat_lancto_id', [TColumnProp.Required])]
    FLanctoFat: Proxy<TLanctoFat>;

As you see, FLanctoFat field is declared as type TLanctoFat, which is not allowed. The parent of the many-valued association should be then of type TLanctoFat` or a class inheriting from it.

ok thanks for the clarification

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.