NOTE: But this DB function got much faster if run directly on DB, without data reference entity data by spring hibernate code in Order entity.
Code:
CREATE OR REPLACE FUNCTION "sample"."getpreviousorders"("_sampleid" varchar, "_mrn" varchar, "_createddate" timestamp)
RETURNS SETOF "sample"."order"