---
title: "SQL-049: Create Subpoena via SaveSubpoena"
summary: Create operation against Subpoena via NHibernate ORM.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Services
reference_type: package
---

# SQL-049: Create Subpoena via SaveSubpoena

This ORM statement performs a create operation on `Subpoena` via `SaveSubpoena`, executed from `Services/SAIF.Services/Legal/Subpoenas/SubpoenaSaveService.cs` (L142).

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-049 |
| **Operation type** | Create |
| **Execution method** | ORM (IRepository.Add) |
| **Database** | Oracle |
| **Schema** | [unqualified]** |
| **Command type** | N/A (ORM-generated) |
| **Business object** | `Subpoena` |
| **Criteria property** | N/A — ORM |
| **Lifecycle method** | `SaveSubpoena` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `:Id` | Input | `long` | N/A | Identifier from `SUBPOENA_SEQ.NEXTVAL` |
| `:UpdateNumber` | Input | `int` | N/A | Version column (`Version()`); NHibernate writes its initial value |
| `:SubpoenaText` | Input | `string` | N/A |  |
| `:SubpoenaOpeningText` | Input | `string` | N/A |  |
| `:ShowAppearanceInstructions` | Input | `bool` | N/A | Bound as `'Y'`/`'N'` (`YesNoType`) |
| `:IssueDate` | Input | `DateTime` | N/A |  |
| `:RequestedByEmployeeId` | Input | `string` | N/A |  |
| `:ApprovedDate` | Input | `DateTime?` | N/A |  |
| `:ApprovedByEmployeeId` | Input | `string` | N/A |  |
| `:AppearanceDateTime` | Input | `DateTime` | N/A |  |
| `:ComplianceDate` | Input | `DateTime` | N/A |  |
| `:BodyPartDescription` | Input | `string` | N/A |  |
| `:RecordsFromDate` | Input | `DateTime?` | N/A |  |
| `:RecordsThruDate` | Input | `DateTime?` | N/A |  |
| `:PageCount` | Input | `long` | N/A |  |
| `:SaifLocationFlag` | Input | `bool` | N/A | Bound as `'Y'`/`'N'` (`YesNoType`) |
| `:AdditionalClaimNumbers` | Input | `string` | N/A |  |
| `:AdditionalCaseNumbers` | Input | `string` | N/A |  |
| `:AKAName` | Input | `string` | N/A |  |
| `:ServeByDate` | Input | `DateTime?` | N/A |  |
| `:SpecificLocations` | Input | `string` | N/A |  |
| `:SpecialDeliveryText` | Input | `string` | N/A |  |
| `:ExternalFileNumber` | Input | `string` | N/A |  |
| `:CreateUser` | Input | `string` | N/A |  |
| `:CreateDate` | Input | `DateTime` | N/A |  |
| `:UpdateUser` | Input | `string` | N/A |  |
| `:UpdateDate` | Input | `DateTime?` | N/A |  |
| `:LegalCase` | Input | `LegalCase` | N/A | Identifier of the referenced `?` entity (`References(x => x.LegalCase)`) |
| `:SubpoenaStatus` | Input | `SubpoenaStatus` | N/A | Identifier of the referenced `SubpoenaStatus` entity (`References(x => x.SubpoenaStatus)`) |
| `:SubpoenaType` | Input | `SubpoenaType` | N/A | Identifier of the referenced `SubpoenaType` entity (`References(x => x.SubpoenaType)`) |
| `:HearingLocation` | Input | `HearingLocation` | N/A | Identifier of the referenced `?` entity (`References(x => x.HearingLocation)`) |
| `:SpecialHandling` | Input | `SubpoenaSpecialHandling` | N/A | Identifier of the referenced `SubpoenaSpecialHandling` entity (`References(x => x.SpecialHandling)`) |
| `:ProcessServerLocation` | Input | `ProviderLocation` | N/A | Identifier of the referenced `ProviderLocation` entity (`References(x => x.ProcessServerLocation)`) |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [SUBPOENA](../database-tables.md#subpoena) | INSERT | SUBPOENA_SEQ_NUM, UPDATE_NUM, SUBPOENA_TEXT, SUBPOENA_OPENING_TEXT, SHOW_APPEARANCE_FLAG, ISSUE_DATE, REQUESTED_BY_EMPLID, APPROVED_DATE, APPROVED_BY_EMPLID, APPEARANCE_DATE_TIME, COMPLIANCE_DATE, BODY_PART_DESC, RECORDS_REQUEST_FROM_DATE, RECORDS_REQUEST_THRU_DATE, PAGE_COUNT, SAIF_LOCATION_FLAG, ADDITIONAL_CLAIM_NUMBERS, ADDITIONAL_CASE_NUMBERS, AKA_NAME, SERVE_BY_DATE, SPECIFIC_LOCATION_TEXT, SPECIAL_DELIVERY_TEXT, FILE_NUMBER, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE, LEGAL_CASE_SEQ_NUM, SUBPOENA_STATUS_CODE, SUBPOENA_TYPE_CODE, HEARING_LOCATION_SEQ_NUM, SPECIAL_HANDLING_CODE, PROCESS_SERVER_LOC_SEQ_NUM (identifier from sequence `SUBPOENA_SEQ.NEXTVAL`) |

## LINQ statement

Source: `Services/SAIF.Services/Legal/Subpoenas/SubpoenaSaveService.cs:142`.

```csharp
// Services/SAIF.Services/Legal/Subpoenas/SubpoenaSaveService.cs:142
_unitOfWork.GetRepository<SubpoenaData.Subpoena>().Add(dataSubpoena);
```

## Sample SQL

> **Inferred SQL:** This SQL was inferred from the LINQ statement above and the NHibernate mappings. It is not concrete SQL from source code; NHibernate generates the executed statement at runtime, so aliases, column order, join syntax, and bind-parameter names may differ.

```sql
-- Inferred from LINQ (NHibernate mapping translation); not concrete SQL
SELECT SUBPOENA_SEQ.NEXTVAL
FROM DUAL

INSERT INTO SUBPOENA (
  SUBPOENA_SEQ_NUM,
  UPDATE_NUM,
  SUBPOENA_TEXT,
  SUBPOENA_OPENING_TEXT,
  SHOW_APPEARANCE_FLAG,
  ISSUE_DATE,
  REQUESTED_BY_EMPLID,
  APPROVED_DATE,
  APPROVED_BY_EMPLID,
  APPEARANCE_DATE_TIME,
  COMPLIANCE_DATE,
  BODY_PART_DESC,
  RECORDS_REQUEST_FROM_DATE,
  RECORDS_REQUEST_THRU_DATE,
  PAGE_COUNT,
  SAIF_LOCATION_FLAG,
  ADDITIONAL_CLAIM_NUMBERS,
  ADDITIONAL_CASE_NUMBERS,
  AKA_NAME,
  SERVE_BY_DATE,
  SPECIFIC_LOCATION_TEXT,
  SPECIAL_DELIVERY_TEXT,
  FILE_NUMBER,
  CREATE_USER,
  CREATE_DATE,
  UPDATE_USER,
  UPDATE_DATE,
  LEGAL_CASE_SEQ_NUM,
  SUBPOENA_STATUS_CODE,
  SUBPOENA_TYPE_CODE,
  HEARING_LOCATION_SEQ_NUM,
  SPECIAL_HANDLING_CODE,
  PROCESS_SERVER_LOC_SEQ_NUM)
VALUES (
  :Id,
  :UpdateNumber,
  :SubpoenaText,
  :SubpoenaOpeningText,
  :ShowAppearanceInstructions,
  :IssueDate,
  :RequestedByEmployeeId,
  :ApprovedDate,
  :ApprovedByEmployeeId,
  :AppearanceDateTime,
  :ComplianceDate,
  :BodyPartDescription,
  :RecordsFromDate,
  :RecordsThruDate,
  :PageCount,
  :SaifLocationFlag,
  :AdditionalClaimNumbers,
  :AdditionalCaseNumbers,
  :AKAName,
  :ServeByDate,
  :SpecificLocations,
  :SpecialDeliveryText,
  :ExternalFileNumber,
  :CreateUser,
  :CreateDate,
  :UpdateUser,
  :UpdateDate,
  :LegalCase,
  :SubpoenaStatus,
  :SubpoenaType,
  :HearingLocation,
  :SpecialHandling,
  :ProcessServerLocation)
```

Translation notes:
- `:Id` is the value fetched from sequence `SUBPOENA_SEQ` (`GeneratedBy.Native("SUBPOENA_SEQ")`) before the INSERT; NHibernate assigns it to `Subpoena.Id`.
- `UPDATE_NUM` is the optimistic-concurrency version column (`Version(x => x.UpdateNumber)`); NHibernate sets its initial value on INSERT.
- `:ShowAppearanceInstructions`, `:SaifLocationFlag` are bound as `'Y'` / `'N'` (`YesNoType`).
- Reference FK values are bound from the associated entity's identifier; the referenced tables are **not** read or joined by this statement: `LegalCase` → `LEGAL_CASE_SEQ_NUM`; `SubpoenaStatus` → `SUBPOENA_STATUS_CODE` (entity table `SUBPOENA_STATUS_CODE` not accessed); `SubpoenaType` → `SUBPOENA_TYPE_CODE` (entity table `SUBPOENA_TYPE_CODE` not accessed); `HearingLocation` → `HEARING_LOCATION_SEQ_NUM`; `SpecialHandling` → `SPECIAL_HANDLING_CODE` (entity table `SUBPOENA_SPECIAL_HANDLING_CODE` not accessed); `ProcessServerLocation` → `PROCESS_SERVER_LOC_SEQ_NUM` (entity table `PROVIDER_LOCATION` not accessed).
- Cascade: `HasMany(x => x.Recipients)` is mapped with `Cascade.AllDeleteOrphan()`; any transient instances in that association are saved in their own statements (not fabricated here).

## Operations and processes
- SubpoenaSaveService.SaveSubpoena — see [Operations and processes](../operations-processes.md)

## Business rules
- [SVC-BR-LGL-095](../business-rules.md#svc-br-lgl-095-subpoena%3A-subpoenatype.code-%22error%3A-subpoena-type-must-be-designated.%22%3B-recipients.count%3E0-%22error%3A-a-subpoena-must-have-at-least-one-recipient.%22%3B-appearancedate-%22error%3A-a-subpoena-must-have-an-appearance-date.%22%3B-appearancetime-%22error%3A-a-subpoena-must-have-an-appearance-time.%22%3B-hearinglocation-%22error%3A-a-subpoena-must-have-a-hearing-location-selected.%22%3B-compliancedate-%22error%3A-a-subpoena-must-have-a-compliance-date.%22%3B-specialhandling-%22error%3A-a-subpoena-must-have-a-special-handling-type-selected.%22%3B-requestedbyemployeeid-%22error%3A-a-subpoena-must-have-a-requesting-attorney.%22%3B-recordsfromdate-required-when-thru-present%3B-recordsthrudate-required-when-from-present%3B-thru-%E2%89%A5-from-%22error%3A-records-thru-date-cannot-be-before-records-from-date.%22%3B-recipient-data-%22error%3A-invalid-or-incomplete-witness-information-entered.%22)
- [SVC-BR-LGL-096](<../business-rules.md#svc-br-lgl-096-recipient-data%3A-records%2Fclaims-types-need-providerlocationid%3E0-and-a-9-char-tin%3B-othermedical%2Fparties%2Fnonparties-need-first-name-1%E2%80%9320%2C-last-name-1%E2%80%9325%2C-and-a-policy-location-or-a-full-address-(line1-5%E2%80%9340%2C-line2-%E2%89%A440%2C-city-2%E2%80%9330%2C-state-2%2C-zip-5%2C-%2B4-empty-or-4)%3B-other-types-invalid>)
- [SVC-BR-LGL-097](../business-rules.md#svc-br-lgl-097-recipient%3A-mileagecost-%E2%89%A50-%22error%3A-mileage-cost-cannot-be-negative.%22%3B-mileageunits-%E2%89%A50-%22error%3A-mileage-units-cannot-be-negative.%22%3B-paidamount-0-or-%E2%89%A5-calculatedpaidamount-%22error%3A-the-paid-amount-cannot-be-less-than-the-calculated-amount.%22)

> **Note:** Statements marked with `**` could not be confirmed; treat as unknown until verified.

## Sources
- `Services/SAIF.Services/Legal/Subpoenas/SubpoenaSaveService.cs (L142)`
