Skip to content

Spanner Features Sample#225

Merged
dzou merged 7 commits intomasterfrom
spanner-features-sample
Nov 4, 2020
Merged

Spanner Features Sample#225
dzou merged 7 commits intomasterfrom
spanner-features-sample

Conversation

@dzou
Copy link
Copy Markdown
Contributor

@dzou dzou commented Nov 3, 2020

Initial commit of the Spanner Features code sample for Hibernate.

Demonstrates:

  • Stale Reads
  • Read-Only Transactions

Open Questions:

From my testing it seems like the Hibernate Sessions share the JDBC Connection. This means that if you set the connection to read-only like this:

    try (Session session = sessionFactory.openSession()) {
      session.beginTransaction();
      session.doWork(connection -> connection.setReadOnly(true));
      ... Do something ...
      session.getTransaction().commit();
    }

You will have to undo that later on by setting the connection to readOnly = false in the next connection. The setting will stay even when you open a new session.

    try (Session session = sessionFactory.openSession()) {
      session.beginTransaction();
      session.doWork(connection -> connection.setReadOnly(false));
      ... Do something ...
      session.getTransaction().commit();
    }

Would this break the multi-threaded use-case though? Will ask.

@dzou dzou merged commit 91bfc1e into master Nov 4, 2020
@dzou dzou deleted the spanner-features-sample branch November 4, 2020 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants