A Session can be used to perform transactions that read and/or modify data in a Cloud
Spanner database.
Sessions can only execute one transaction at a time. To execute multiple concurrent
read-write/write-only transactions, create multiple sessions. Note that standalone reads and
queries use a transaction internally, and count toward the one transaction limit.
It is a good idea to delete idle and/or unneeded sessions. Aside from explicit deletes, Cloud
Spanner can delete sessions for which no operations are sent for more than an hour, or due to
internal errors. If a session is deleted, requests to it return ErrorCode#NOT_FOUND.
Idle sessions can be kept alive by sending a trivial SQL query periodically, for example,
SELECT 1.
Sessions are long-lived objects intended to be reused for many consecutive operations; a
typical application will maintain a pool of sessions to use during its lifetime.
Since only one transaction can be performed at a time within any given session, instances
require external synchronization; Session implementations are not required to be
thread-safe.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Interface Session (6.98.1)\n\nVersion latestkeyboard_arrow_down\n\n- [6.98.1 (latest)](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Session)\n- [6.98.0](/java/docs/reference/google-cloud-spanner/6.98.0/com.google.cloud.spanner.Session)\n- [6.97.1](/java/docs/reference/google-cloud-spanner/6.97.1/com.google.cloud.spanner.Session)\n- [6.96.1](/java/docs/reference/google-cloud-spanner/6.96.1/com.google.cloud.spanner.Session)\n- [6.95.1](/java/docs/reference/google-cloud-spanner/6.95.1/com.google.cloud.spanner.Session)\n- [6.94.0](/java/docs/reference/google-cloud-spanner/6.94.0/com.google.cloud.spanner.Session)\n- [6.93.0](/java/docs/reference/google-cloud-spanner/6.93.0/com.google.cloud.spanner.Session)\n- [6.89.0](/java/docs/reference/google-cloud-spanner/6.89.0/com.google.cloud.spanner.Session)\n- [6.88.0](/java/docs/reference/google-cloud-spanner/6.88.0/com.google.cloud.spanner.Session)\n- [6.87.0](/java/docs/reference/google-cloud-spanner/6.87.0/com.google.cloud.spanner.Session)\n- [6.86.0](/java/docs/reference/google-cloud-spanner/6.86.0/com.google.cloud.spanner.Session)\n- [6.85.0](/java/docs/reference/google-cloud-spanner/6.85.0/com.google.cloud.spanner.Session)\n- [6.83.0](/java/docs/reference/google-cloud-spanner/6.83.0/com.google.cloud.spanner.Session)\n- [6.82.0](/java/docs/reference/google-cloud-spanner/6.82.0/com.google.cloud.spanner.Session)\n- [6.80.1](/java/docs/reference/google-cloud-spanner/6.80.1/com.google.cloud.spanner.Session)\n- [6.79.0](/java/docs/reference/google-cloud-spanner/6.79.0/com.google.cloud.spanner.Session)\n- [6.77.0](/java/docs/reference/google-cloud-spanner/6.77.0/com.google.cloud.spanner.Session)\n- [6.74.1](/java/docs/reference/google-cloud-spanner/6.74.1/com.google.cloud.spanner.Session)\n- [6.72.0](/java/docs/reference/google-cloud-spanner/6.72.0/com.google.cloud.spanner.Session)\n- [6.71.0](/java/docs/reference/google-cloud-spanner/6.71.0/com.google.cloud.spanner.Session)\n- [6.69.0](/java/docs/reference/google-cloud-spanner/6.69.0/com.google.cloud.spanner.Session)\n- [6.68.0](/java/docs/reference/google-cloud-spanner/6.68.0/com.google.cloud.spanner.Session)\n- [6.66.0](/java/docs/reference/google-cloud-spanner/6.66.0/com.google.cloud.spanner.Session)\n- [6.65.1](/java/docs/reference/google-cloud-spanner/6.65.1/com.google.cloud.spanner.Session)\n- [6.62.0](/java/docs/reference/google-cloud-spanner/6.62.0/com.google.cloud.spanner.Session)\n- [6.60.0](/java/docs/reference/google-cloud-spanner/6.60.0/com.google.cloud.spanner.Session)\n- [6.58.0](/java/docs/reference/google-cloud-spanner/6.58.0/com.google.cloud.spanner.Session)\n- [6.57.0](/java/docs/reference/google-cloud-spanner/6.57.0/com.google.cloud.spanner.Session)\n- [6.56.0](/java/docs/reference/google-cloud-spanner/6.56.0/com.google.cloud.spanner.Session)\n- [6.55.0](/java/docs/reference/google-cloud-spanner/6.55.0/com.google.cloud.spanner.Session)\n- [6.54.0](/java/docs/reference/google-cloud-spanner/6.54.0/com.google.cloud.spanner.Session)\n- [6.53.0](/java/docs/reference/google-cloud-spanner/6.53.0/com.google.cloud.spanner.Session)\n- [6.52.1](/java/docs/reference/google-cloud-spanner/6.52.1/com.google.cloud.spanner.Session)\n- [6.51.0](/java/docs/reference/google-cloud-spanner/6.51.0/com.google.cloud.spanner.Session)\n- [6.50.1](/java/docs/reference/google-cloud-spanner/6.50.1/com.google.cloud.spanner.Session)\n- [6.49.0](/java/docs/reference/google-cloud-spanner/6.49.0/com.google.cloud.spanner.Session)\n- [6.25.1](/java/docs/reference/google-cloud-spanner/6.25.1/com.google.cloud.spanner.Session)\n- [6.24.0](/java/docs/reference/google-cloud-spanner/6.24.0/com.google.cloud.spanner.Session)\n- [6.23.4](/java/docs/reference/google-cloud-spanner/6.23.4/com.google.cloud.spanner.Session)\n- [6.22.0](/java/docs/reference/google-cloud-spanner/6.22.0/com.google.cloud.spanner.Session)\n- [6.21.2](/java/docs/reference/google-cloud-spanner/6.21.2/com.google.cloud.spanner.Session)\n- [6.20.0](/java/docs/reference/google-cloud-spanner/6.20.0/com.google.cloud.spanner.Session)\n- [6.19.1](/java/docs/reference/google-cloud-spanner/6.19.1/com.google.cloud.spanner.Session)\n- [6.18.0](/java/docs/reference/google-cloud-spanner/6.18.0/com.google.cloud.spanner.Session)\n- [6.17.4](/java/docs/reference/google-cloud-spanner/6.17.4/com.google.cloud.spanner.Session)\n- [6.14.1](/java/docs/reference/google-cloud-spanner/6.14.1/com.google.cloud.spanner.Session) \n\n public interface Session extends DatabaseClient, AutoCloseable\n\nA `Session` can be used to perform transactions that read and/or modify data in a Cloud\nSpanner database.\n\nSessions can only execute one transaction at a time. To execute multiple concurrent\nread-write/write-only transactions, create multiple sessions. Note that standalone reads and\nqueries use a transaction internally, and count toward the one transaction limit.\n\nIt is a good idea to delete idle and/or unneeded sessions. Aside from explicit deletes, Cloud\nSpanner can delete sessions for which no operations are sent for more than an hour, or due to\ninternal errors. If a session is deleted, requests to it return [ErrorCode#NOT_FOUND](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ErrorCode#com_google_cloud_spanner_ErrorCode_NOT_FOUND).\n\nIdle sessions can be kept alive by sending a trivial SQL query periodically, for example,\n`SELECT 1`.\n\nSessions are long-lived objects intended to be reused for many consecutive operations; a\ntypical application will maintain a pool of sessions to use during its lifetime.\n\nSince only one transaction can be performed at a time within any given session, instances\nrequire external synchronization; `Session` implementations are not required to be\nthread-safe. \n\nImplements\n----------\n\n[DatabaseClient](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.DatabaseClient), [AutoCloseable](https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html)\n\nMethods\n-------\n\n### asyncClose()\n\n public abstract ApiFuture\u003cEmpty\u003e asyncClose()\n\nCloses the session asynchronously and returns the [ApiFuture](https://cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html) that can be used to monitor\nthe operation progress.\n\n### close()\n\n public abstract void close()\n\n### getName()\n\n public abstract String getName()\n\nReturns the resource name associated with this session."]]