static void runReadOnlyTransaction()

in google-cloud-spanner-hibernate-samples/basic-spanner-features-sample/src/main/java/com/example/TransactionTypeDemo.java [45:66]


  static void runReadOnlyTransaction(SessionHelper sessionHelper) {
    System.out.println("======== Read-only Transaction Demo ========");

    try (Session session = sessionHelper.createReadOnlySession()) {
      session.beginTransaction();
      Book book = new Book("Programming Guide", "Author");
      session.save(book);
      session.getTransaction().commit();
    } catch (PersistenceException ex) {
      System.out.println(
          "You will get the following error if you try to modify the tables in "
              + "a read-only transaction: ");

      Throwable throwable = ex;
      while (throwable != null) {
        System.out.println("\t" + throwable.getMessage());
        throwable = throwable.getCause();
      }
    }

    System.out.println("==========================");
  }