Integrate Spanner with Spring Data JPA (GoogleSQL dialect)

Spring Data JPA, part of the larger Spring Data family, makes it easier to implement JPA based repositories. Spring Data JPA supports Spanner and a wide range of other database systems. It adds an abstraction layer between your application and your database that makes your application easier to port from one database system to another.

Set up Spring Data JPA for Spanner GoogleSQL-dialect databases

You can integrate Spanner GoogleSQL-dialect databases with Spring Data JPA using the open source Spanner Hibernate Dialect (SpannerDialect).

To see an example, refer to the full working sample application on GitHub.


In your project, add Apache Maven dependencies for Spring Data JPA, Spanner Hibernate Dialect, and the Spanner officially supported Open Source JDBC driver.

    <!-- Spring Data JPA -->
    <!-- Hibernate Dialect and JDBC Driver dependencies-->


Configure to use the Spanner Hibernate Dialect and the Spanner JDBC Driver.

# Spanner connection URL.
# - ${PROJECT_ID} Replace with your GCP project ID
# - ${INSTANCE_ID} Replace with your Spanner instance ID
# - ${DATABASE_NAME} Replace with the name of your Spanner database that you created inside your Spanner instance


# Specify the Spanner JDBC driver.

# Specify the Spanner Hibernate dialect.


# Settings to enable batching statements for efficiency

# You can display SQL statements and stats for debugging if needed.

Full Sample Application

A working sample application is available on GitHub.

What's next