A transaction type that provides guaranteed consistency across several reads, but does not allow
writes. Snapshot read-only transactions can be configured to read at timestamps in the past.
Snapshot read-only transactions do not need to be committed.
Snapshot read-only transactions provide a simpler method than locking read-write transactions
for doing several consistent reads. However, this type of transaction does not support writes.
Snapshot read-only transactions do not take locks. Instead, they work by choosing a Cloud
Spanner timestamp, then executing all reads at that timestamp. Since they do not acquire locks,
they do not block concurrent read-write transactions.
Unlike locking read-write transactions, snapshot read-only transactions never abort. They can
fail if the chosen read timestamp is garbage collected; however, the default garbage collection
policy is generous enough that most applications do not need to worry about this in practice. See
the class documentation of TimestampBound for more details.
To execute a snapshot transaction, specify a TimestampBound, which tells Cloud Spanner
how to choose a read timestamp.
See Also: Session#readOnlyTransaction(TimestampBound), Session#singleUseReadOnlyTransaction(TimestampBound)
Returns the timestamp chosen to perform reads and queries in this transaction. The value can
only be read after some read or query has either returned some data or completed without
returning any data.
[[["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 ReadOnlyTransaction (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.ReadOnlyTransaction)\n- [6.98.0](/java/docs/reference/google-cloud-spanner/6.98.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.97.1](/java/docs/reference/google-cloud-spanner/6.97.1/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.96.1](/java/docs/reference/google-cloud-spanner/6.96.1/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.95.1](/java/docs/reference/google-cloud-spanner/6.95.1/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.94.0](/java/docs/reference/google-cloud-spanner/6.94.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.93.0](/java/docs/reference/google-cloud-spanner/6.93.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.89.0](/java/docs/reference/google-cloud-spanner/6.89.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.88.0](/java/docs/reference/google-cloud-spanner/6.88.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.87.0](/java/docs/reference/google-cloud-spanner/6.87.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.86.0](/java/docs/reference/google-cloud-spanner/6.86.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.85.0](/java/docs/reference/google-cloud-spanner/6.85.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.83.0](/java/docs/reference/google-cloud-spanner/6.83.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.82.0](/java/docs/reference/google-cloud-spanner/6.82.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.80.1](/java/docs/reference/google-cloud-spanner/6.80.1/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.79.0](/java/docs/reference/google-cloud-spanner/6.79.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.77.0](/java/docs/reference/google-cloud-spanner/6.77.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.74.1](/java/docs/reference/google-cloud-spanner/6.74.1/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.72.0](/java/docs/reference/google-cloud-spanner/6.72.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.71.0](/java/docs/reference/google-cloud-spanner/6.71.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.69.0](/java/docs/reference/google-cloud-spanner/6.69.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.68.0](/java/docs/reference/google-cloud-spanner/6.68.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.66.0](/java/docs/reference/google-cloud-spanner/6.66.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.65.1](/java/docs/reference/google-cloud-spanner/6.65.1/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.62.0](/java/docs/reference/google-cloud-spanner/6.62.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.60.0](/java/docs/reference/google-cloud-spanner/6.60.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.58.0](/java/docs/reference/google-cloud-spanner/6.58.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.57.0](/java/docs/reference/google-cloud-spanner/6.57.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.56.0](/java/docs/reference/google-cloud-spanner/6.56.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.55.0](/java/docs/reference/google-cloud-spanner/6.55.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.54.0](/java/docs/reference/google-cloud-spanner/6.54.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.53.0](/java/docs/reference/google-cloud-spanner/6.53.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.52.1](/java/docs/reference/google-cloud-spanner/6.52.1/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.51.0](/java/docs/reference/google-cloud-spanner/6.51.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.50.1](/java/docs/reference/google-cloud-spanner/6.50.1/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.49.0](/java/docs/reference/google-cloud-spanner/6.49.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.25.1](/java/docs/reference/google-cloud-spanner/6.25.1/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.24.0](/java/docs/reference/google-cloud-spanner/6.24.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.23.4](/java/docs/reference/google-cloud-spanner/6.23.4/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.22.0](/java/docs/reference/google-cloud-spanner/6.22.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.21.2](/java/docs/reference/google-cloud-spanner/6.21.2/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.20.0](/java/docs/reference/google-cloud-spanner/6.20.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.19.1](/java/docs/reference/google-cloud-spanner/6.19.1/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.18.0](/java/docs/reference/google-cloud-spanner/6.18.0/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.17.4](/java/docs/reference/google-cloud-spanner/6.17.4/com.google.cloud.spanner.ReadOnlyTransaction)\n- [6.14.1](/java/docs/reference/google-cloud-spanner/6.14.1/com.google.cloud.spanner.ReadOnlyTransaction) \n\n public interface ReadOnlyTransaction extends ReadContext\n\nA transaction type that provides guaranteed consistency across several reads, but does not allow\nwrites. Snapshot read-only transactions can be configured to read at timestamps in the past.\nSnapshot read-only transactions do not need to be committed.\n\nSnapshot read-only transactions provide a simpler method than locking read-write transactions\nfor doing several consistent reads. However, this type of transaction does not support writes.\n\nSnapshot read-only transactions do not take locks. Instead, they work by choosing a Cloud\nSpanner timestamp, then executing all reads at that timestamp. Since they do not acquire locks,\nthey do not block concurrent read-write transactions.\n\nUnlike locking read-write transactions, snapshot read-only transactions never abort. They can\nfail if the chosen read timestamp is garbage collected; however, the default garbage collection\npolicy is generous enough that most applications do not need to worry about this in practice. See\nthe class documentation of [TimestampBound](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.TimestampBound) for more details.\n\nTo execute a snapshot transaction, specify a [TimestampBound](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.TimestampBound), which tells Cloud Spanner\nhow to choose a read timestamp.\nSee Also: Session#readOnlyTransaction(TimestampBound), Session#singleUseReadOnlyTransaction(TimestampBound) \n\nImplements\n----------\n\n[ReadContext](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext)\n\nMethods\n-------\n\n### getReadTimestamp()\n\n public abstract Timestamp getReadTimestamp()\n\nReturns the timestamp chosen to perform reads and queries in this transaction. The value can\nonly be read after some read or query has either returned some data or completed without\nreturning any data."]]