I have the following entitles:
[Entity]
[Table('QUsurvey')]
[Id('FSID', TIdGenerator.IdentityOrSequence)]
TQUsurvey = class
private
[Column('SID', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
FSID: Integer;
public
property SID: Integer read FSID write FSID;
end;
[Entity]
[Table('QUframe')]
[Id('FFID', TIdGenerator.IdentityOrSequence)]
TQUframe = class
private
[Column('FID', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
FFID: Integer;
[Association([TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('SID', [TColumnProp.Required], 'SID')]
Fsurvey: TQUSurvey;
public
property FID: Integer read FFID write FFID;
property survey: TQUsurvey read Fsurvey write Fsurvey;
end;
[Entity]
[Table('QUquestion')]
[Id('FQID', TIdGenerator.IdentityOrSequence)]
TQUquestion = class
private
[Column('QID', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
FQID: Integer;
[Association([TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('SID', [TColumnProp.Required], 'SID')]
Fsurvey: TQUsurvey;
[Association([TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('FID', [TColumnProp.Required], 'FID')]
Fframe: TQUframe;
public
property QID: Integer read FQID write FQID;
property survey: TQUsurvey read Fsurvey write Fsurvey;
property frame: TQUframe read Fframe write Fframe;
end;
Other not related files are deleted. I am using TXDataClient to do all functions to the db.
I am creating a new TQUframe and I assign in TQUframe.survey the TQUsurvey I have requested before. I can POST the new TQUframe and everything is OK
Now I am creating a TQUquestion and I assign in TQUquestion.frame the existing TQUframe I requested before and in TQUquestion.survey the TQUsurvey I have also requested before.
I try to POST the new TQUquestion and I am getting:
ObjectAlreadyPersistent: Cannot turn persistent object of class TQUsurvey with id 1. The object is already in persistent context.
What am I doing wrong?
Thank you in advance