Association...

hello, i'am a newby on this forum, so perhaps i made a mistake in my code !.
 
I have two objects declared like this
 
  [Entity, Table('session')]
  [Id('FSessionId', TIdGenerator.IdentityOrSequence)]
  TSession = Class(TinterfacedPersistent)
  Private
    [Column('SessionId', [TColumnProp.Unique, TColumnProp.Required])]
    FSessionId: Int64;
 
    [ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAll, 'FSession')]
    FEntretiens : Proxy<TList<TEntretien>>;
 
    function GetEntretiens: TList<TEntretien>;
  Public
    property SessionId: Int64 read FSessionId write FSessionId;
    property Entretiens : TList<TEntretien> read GetEntretiens;
  end;
 
  [Entity, Table('Entretien')]
  [Id('FId', TIdGenerator.IdentityOrSequence)]
  TEntretien = class(TinterfacedPersistent)
  private
    [Column('Id', [TColumnProp.Unique, TColumnProp.Required])]
    FId: Int64;
    
    [Association([TAssociationProp.Required], [])]
    [JoinColumn('SessionId', [TColumnProp.Required])]
    FSession : Proxy<TSession>;
 
    function GetCandidat: TProspect;
    procedure SetCandidat(const Value: TProspect);
  Public
    Property SessionId : Int64 read FSessionId write FSessionId;
    Property Candidat : TProspect read GetCandidat write SetCandidat;
  End ;
 
When I load the TSession list using this code :
 
  SessionList :=Manager.Find<TSession>.list;
  for I := 0 to SessionList.Count-1 do
  begin
    Memo1.Lines.Add(SessionList.Libelle);
    for J := 0 to SessionList.Entretiens.Count-1 do
    begin
      Memo1.Lines.Add(SessionList.Entretiens[J].Libelle);
    end;
  end;
  SessionList.Free;
 
I have a Stack overflow exception :  it seems that the Tsession object is detroy and recreated when the Tentretien is loaded and the «entretiens »  list is accessed…
 
Where i made a mistake ?
 
Thank you for your help !
PLT




Hi,

What is Libelle?
Where exactly the error occurs?
What do you have in your GetEntretiens method?
Are you creating the FEntretiens object list in your TSession constructor?


"Libelle" is a property define in the object like this:

[Colum('Libelle,[],255)]
FLibelle : String;
...
property libelle : String read FLibelle write FLibelle; 

for clarity i did not put all the declarations of the object 

The Methode GetEntretiens is declared like this :

function Tsession.GetEntretiens: TList<TEntretien>;
begin
  if Not Assigned(FEntretiens.Value) then
    FEntretiens.SetInitialValue(TList<TEntretien>.create);
  Result:=FEntretiens.Value;
end;

The Session constructor is like this : 

constructor TSession.Create;
begin
  Inherited Create;
  FEntretiens.SetInitialValue(Nil);
  ...
end;





Where does the error occurs? Can you get the call stack so we can easily have an idea of where the stack overflow is occurring? Unfortunately I can't tell what's wrong with the information provided so far.