Question Smythe Smythee · Mar 23, 2023

Saving data into SQL table

Hi Community,

I am trying to save data into SQL table but each entry  getting saved twice in the SQL table. Is there any reason data is saving Twice in the SQL table 

I have created a %Persistent class for the fields

Please find the business operation below

 

Class Patient.DBOperation Extends Ens.BusinessOperation

{

Parameter ADAPTER = "EnsLib.SQL.OutboundAdapter";

Property Adapter As EnsLib.SQL.OutboundAdapter;

Parameter INVOCATION = "Queue";

Method OnMessage(pInput As Patient.PatientDBReq, pOutput As Ens.Response) As %Status
{
    Set Entry=##class(Patient.PatientDBReq).%New()
    Set Entry.PatientID=pInput.PatientID
    Set Entry.AdmDateandTime=pInput.AdmDateandTime
    Set sc=Entry.%Save()
    $$$LOGINFO("Onmessage "_"`"_sc)
    Quit sc
}

}

Patient.PatientDBReq Class

Class Patient.PatientDBReq Extends Ens.Request
{

Property PatientID As %Numeric;

Property AdmDateandTime As %DateTime;

}

 

Thanks,

Smythee

Product version: Ensemble 2018.1
$ZV: Cache for Windows (x86-64) 2018.1.1 (Build 312_1_18937U) Fri Apr 26 2019 17:58:36 EDT

Comments

Oliver Wilms · Mar 23, 2023

pInput As Patient.PatientDBReq is automatically persisted. You do not need to explicitly call %Save()

0
Smythe Smythee  Mar 23, 2023 to Oliver Wilms

Hi Oliver Wilms 

I have used   Ens.Request Extension class for Patient.PatientDBReq , the Ens.Request class is like below 

Class Ens.Request Extends (Ens.MessageBody, Ens.Util.RequestBodyMethods) -->Can you please tell how it will be saved without calling %Save()?

So if i use  %Persistent  Extension class for Patient.PatientDBReq  class do i need to call %Save() for saving data into SQL table?

Smythe

0
Oliver Wilms  Mar 23, 2023 to Smythe Smythee

I understand your original question was why the data was saved twice. I would try to comment out the %Save() and see if you get new data one time.

0
Smythe Smythee  Mar 23, 2023 to Oliver Wilms

yes i have commented out %Save() and it worked data is saving only once in the SQL table 

and i have checked in Extended classes also but i am not able to find how it is getting saved in SQL table without even Calling %Save()

0
Oliver Wilms  Mar 23, 2023 to Smythe Smythee

The object is passed to the SQL Outbound operation. It is a Ens.StreamContainer and Ens.Request which are automatically persisted, meaning saved into the table.

0