You have an error in your SQL syntax


I'm experiencing this error when saving a new entity:
'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''#2')'' at line 4'

vMyObject:= TMyClass.Create(field1, field2....);
vMyObjManager.SaveOrUpdate(vMyObject); << HERE THERE ERROR IS RAISED

I'm using a MySQL DB.

The error appear at random, doing the same operation sometimes appear, sometimes not

My class:
// TExamination
  [Id('FId', TIdGenerator.IdentityOrSequence)]
TExamination = class
  strict private
    [Column('ID', [TColumnProp.Unique, TColumnProp.Required, TColumnProp.NoUpdate])]
    FId: Integer;
    [Association([], [TCascadeType.SaveUpdate])]
    [JoinColumn('PatientID', [TColumnProp.Required])]
    FPatient: Proxy<TPatient>;

    [Column('ExaminationDateTime', [])]
    FExaminationDateTime: TDateTime;

    [Column('PatientHeight', [])]
    FPatientHeight: Integer;

    [Column('PatientWeight', [])]
    FPatientWeight: Integer;

    [Column('ExaminationType', [TColumnProp.Required])]
    FExaminationType: Integer;

    [Column('Diagnosis', [TColumnProp.Lazy])]
    FDiagnosis: TBlob;

    [Column('Therapy', [TColumnProp.Lazy])]
    FTherapy: TBlob;

    [ManyValuedAssociation([], CascadeTypeAll, 'FExamination')]
    FPhotos: Proxy<TList<TExaminationPhoto>>;

    [Column('LimbLengthShorterRight', [])]
    FLimbLengthShorterRight: Integer;

    [Column('LimbLengthShorterLeft', [])]
    FLimbLengthShorterLeft: Integer;

    [Column('LasegueSignRight', [])]
    FLasegueSignRight: Integer;

    [Column('LasegueSignLeft', [])]
    FLasegueSignLeft: Integer;

    [Column('FootInternalRotationRight', [])]
    FFootInternalRotationRight: Integer;

    [Column('FootInternalRotationLeft', [])]
    FFootInternalRotationLeft: Integer;

    [Column('TMJRight', [], 500)]
    FTMJRight: String;

    [Column('TMJLeft', [], 500)]
    FTMJLeft: String;

    [Column('TemporalMAnteriorRight', [], 500)]
    FTemporalMAnteriorRight: String;

    [Column('TemporalMAnteriorLeft', [], 500)]
    FTemporalMAnteriorLeft: String;

    [Column('MasseterMRight', [], 500)]
    FMasseterMRight: String;

    [Column('MasseterMLeft', [], 500)]
    FMasseterMLeft: String;

    [Column('SternocleidomastoideusMRight', [], 500)]
    FSternocleidomastoideusMRight: String;

    [Column('SternocleidomastoideusMLeft', [], 500)]
    FSternocleidomastoideusMLeft: String;

    [Column('SartoriusMRight', [], 500)]
    FSartoriusMRight: String;

    [Column('SartoriusMLeft', [], 500)]
    FSartoriusMLeft: String;

    [Column('ShoulderRight', [], 500)]
    FShoulderRight: String;

    [Column('ShoulderLeft', [], 500)]
    FShoulderLeft: String;

    [Column('ScapulaRight', [], 500)]
    FScapulaRight: String;

    [Column('ScapulaLeft', [], 500)]
    FScapulaLeft: String;

    [Column('SideRight', [], 500)]
    FSideRight: String;

    [Column('SideLeft', [], 500)]
    FSideLeft: String;

    [Column('Overhang', [], 500)]
    FOverhang: String;

    [Column('Kyphosis', [], 500)]
    FKyphosis: String;

    [Column('Lordosis', [], 500)]
    FLordosis: String;

    [Column('ProximalCostalTorsion', [], 500)]
    FProximalCostalTorsion: String;

    [Column('LombarTorsion', [], 500)]
    FLombarTorsion: String;

    [Column('Bending', [], 500)]
    FBending: String;

    [Column('SiasRight', [], 500)]
    FSiasRight: String;

    [Column('SiasLeft', [], 500)]
    FSiasLeft: String;

    [Column('Height', [])]
    FHeight: Integer;

    [Column('Weight', [])]
    FWeight: Integer;

    [Column('RetractionIT', [])]
    FRetractionIT: Integer;

    [Column('RadiographAP', [])]
    FRadiographAP: Integer;

    [Column('RadiographLat', [])]
    FRadiographLat: Integer;

    [Column('RadiographTorsion', [], 500)]
    FRadiographTorsion: String;

    [Column('RadiographRisser', [], 500)]
    FRadiographRisser: String;

    [Column('RadiographHips', [], 500)]
    FRadiographHips: String;

    [Column('RadiographSpondylolisthesis', [], 500)]
    FRadiographSpondylolisthesis: String;

    [Column('ItemStatus', [])]
    FItemStatus: Integer;

What is the SQL statement generated by Aurelius that is causing the problem?

One wrong thing I see in your mapping is that since you are using SIngleTable inheritance, you must specify DiscriminatorColumn attribute (in root class) and DiscriminatorValue attribute (in inherited classes) for it to work correctly.

How can I extract the SQL generated?

As I haven't a class hierarchy, I will try removing the inheritance definition.

You can use the profiler of your database, or you can use the command listener. If you check Music Library demo, there is an example there of how to monitor the generated SQL.