Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.adoc Link to the codelab in the solution (#160) Nov 15, 2019
pom.xml Move master to 1.1.0-SNAPSHOT (#163) Nov 15, 2019


Cloud Spanner Hibernate Codelab Solution

This is the solution for the Cloud Spanner with Hibernate ORM Codelab.

Setup & Configuration

  1. Create a Google Cloud Platform project.

  2. Create a service account with Cloud Spanner permission. Furnish a new JSON key and then set the credentials using the GOOGLE_APPLICATION_CREDENTIALS environment variable.

    Alternatively, have the Google Cloud SDK installed and initialized and logged in with application default credentials.

    gcloud auth application-default login
  3. Enable the Cloud Spanner API

    gcloud services enable
  4. Create a Cloud Spanner instance and database in your project and save those details for the next step.

    gcloud spanner instances create codelab-instance \
     --config=regional-us-central1 \
     --description="Codelab Instance" --nodes=1
    gcloud spanner databases create codelab-db --instance=codelab-instance
  5. Update src/main/resources/ so that the connection refers to your project ID and database coordinates.


Run the Example

Run the example main method in

mvn compile exec:java -Dexec.mainClass=codelab.App -Dexec.cleanupDaemonThreads=false

You should see something like this in the console output:

Singers who were born in 1990 or later:
Jacqueline Long born on 1990-07-29
Dylan Shaw born on 1998-05-02
"Go, Go, Go" by Melissa Garcia

Delete the Cloud Spanner instance

Only do this if you created the instance specifically for running this sample and nothing else.
gcloud spanner instances delete codelab-instance
You can’t perform that action at this time.