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

# SQL-308: Retrieve Subpoena

This statement retrieves a single subpoena by its identifier from `SUBPOENA` via NHibernate LINQ over `IUnitOfWork.GetRepository<Subpoena>()`. It is executed by `SubpoenaSaveService.DeleteSubpoena` and `SubpoenaSaveService.SaveSubpoena` (`Services/SAIF.Services/Legal/Subpoenas/SubpoenaSaveService.cs (L84, L114)`) to load the subpoena that is subsequently deleted or updated.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-308 |
| **Operation type** | Read |
| **Execution method** | ORM (NHibernate LINQ) |
| **Database** | Oracle |
| **Schema** | [unqualified]** |
| **Command type** | N/A (ORM-generated) |
| **Business object** | `SubpoenaSaveService` |
| **Criteria property** | N/A — ORM |
| **Lifecycle method** | `DeleteSubpoena, SaveSubpoena` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `:subpoenaId` | Input | Long | N/A | `subpoenaId` (L84) matched against `SUBPOENA_SEQ_NUM` in `DeleteSubpoena` |
| `:subpoenaId` | Input | Long | N/A | `subpoena.Id` (L114) matched against `SUBPOENA_SEQ_NUM` in `SaveSubpoena` |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [SUBPOENA](../database-tables.md#subpoena) | SELECT | `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` |

## LINQ statement

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

```csharp
// Services/SAIF.Services/Legal/Subpoenas/SubpoenaSaveService.cs:83-84
var subpoena =
    _unitOfWork.GetRepository<SubpoenaData.Subpoena>().Query().FirstOrDefault(x => x.Id == subpoenaId);

// Services/SAIF.Services/Legal/Subpoenas/SubpoenaSaveService.cs:113-115
var dataSubpoena =
    _unitOfWork.GetRepository<SubpoenaData.Subpoena>().Query().FirstOrDefault(x => x.Id == subpoena.Id) ??
    new SubpoenaData.Subpoena();
```

## 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 *
FROM (
  SELECT
    S.SUBPOENA_SEQ_NUM,
    S.UPDATE_NUM,
    S.SUBPOENA_TEXT,
    S.SUBPOENA_OPENING_TEXT,
    S.SHOW_APPEARANCE_FLAG,
    S.ISSUE_DATE,
    S.REQUESTED_BY_EMPLID,
    S.APPROVED_DATE,
    S.APPROVED_BY_EMPLID,
    S.APPEARANCE_DATE_TIME,
    S.COMPLIANCE_DATE,
    S.BODY_PART_DESC,
    S.RECORDS_REQUEST_FROM_DATE,
    S.RECORDS_REQUEST_THRU_DATE,
    S.PAGE_COUNT,
    S.SAIF_LOCATION_FLAG,
    S.ADDITIONAL_CLAIM_NUMBERS,
    S.ADDITIONAL_CASE_NUMBERS,
    S.AKA_NAME,
    S.SERVE_BY_DATE,
    S.SPECIFIC_LOCATION_TEXT,
    S.SPECIAL_DELIVERY_TEXT,
    S.FILE_NUMBER,
    S.CREATE_USER,
    S.CREATE_DATE,
    S.UPDATE_USER,
    S.UPDATE_DATE,
    S.LEGAL_CASE_SEQ_NUM,
    S.SUBPOENA_STATUS_CODE,
    S.SUBPOENA_TYPE_CODE,
    S.HEARING_LOCATION_SEQ_NUM,
    S.SPECIAL_HANDLING_CODE,
    S.PROCESS_SERVER_LOC_SEQ_NUM
  FROM SUBPOENA S
  WHERE S.SUBPOENA_SEQ_NUM = :subpoenaId
)
WHERE ROWNUM <= 1
```

Translation notes:
- The `Delete` at L87-88 is a separate write statement.
- `First`/`FirstOrDefault` → Oracle10 dialect row limit `SELECT * FROM (...) WHERE ROWNUM <= 1`.
- `References` (`LegalCase`, `SubpoenaStatus`, `SubpoenaType`, `HearingLocation`, `SpecialHandling`, `ProcessServerLocation`) contribute FK columns only; `HasMany(Recipients)` is lazy — `subpoena.Recipients.Any()` after materialization triggers a separate lazy collection load that is not part of this statement.

## Operations and processes
- SubpoenaSaveService.DeleteSubpoena — see [Operations and processes](../operations-processes.md)
- 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)

## Sources
- `Services/SAIF.Services/Legal/Subpoenas/SubpoenaSaveService.cs (L84, L114)`
