# Java persistence decision worksheet

Source: https://yenra.com/database-persistence-tool-for-java/
Purpose: choose a data-access approach using a representative workload.
Compare JDBC, SQL mapping and ORM against the same schema and expected results.
Record exact versions and actual observations. Blank fields are to be completed;
the example counts below are illustrative arithmetic, not benchmark results.

Project, reviewer, date:
Database/version, JDBC driver/version, framework/version, JDK:
Schema owner and migration mechanism:
Transaction owner:

## Representative scenario
Example: list 20 orders with customer names and each order's line-item count.
Fix sort order; include an order with no lines and two orders with the same date.
Expected one row per order; counts should be 0 for an order with no lines.
Pagination must apply to orders, not to individual joined line-item rows.

| Measure | JDBC | SQL mapper | ORM |
|---|---|---|---|
| Result correctness, zero-line case and stable order | | | |
| SQL statements issued (observed) | | | |
| Rows and bytes returned (observed) | | | |
| Transaction boundary and rollback evidence | | | |
| Query-plan/index observations | | | |
| Concurrent-write behavior and conflict handling | | | |
| Ease of changing a query and inspecting SQL | | | |
| Migration, deployment and team ownership | | | |

## Query-count arithmetic (fictional)
One query for 20 orders plus one line-count query per order is 1+20=21 queries.
A deliberate aggregate query may return the same result in one query.
Neither count establishes elapsed time: inspect rows, plans, indexes and workload.
For a two-query strategy, obtain the page of order IDs then fetch counts for those IDs.

## Decision record
Selected approach and the requirements it satisfies:
Reasons the alternatives fit less well:
Measured evidence, dataset and reproduction commands:
Unresolved tradeoffs, owner and review date:
Revisit when query patterns, relationships, database features or team skills change.

Primary references:
https://docs.oracle.com/en/java/javase/25/docs/api/java.sql/java/sql/package-summary.html
https://mybatis.org/mybatis-3/sqlmap-xml.html
https://jakarta.ee/specifications/persistence/3.2/jakarta-persistence-spec-3.2
