Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spanner Features Sample #225

Merged
merged 7 commits into from Nov 4, 2020
Merged

Spanner Features Sample #225

merged 7 commits into from Nov 4, 2020

Conversation

dzou
Copy link
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.

None yet

2 participants