Integrate Spanner with Hibernate ORM (GoogleSQL dialect)
Stay organized with collections
Save and categorize content based on your preferences.
Hibernate is an object-relational mapping tool for the Java programming language.
It provides a framework for mapping an object-oriented domain model to a relational database.
You can integrate GoogleSQL-dialect databases with Hibernate using the open source
Spanner Dialect
(SpannerDialect). Spanner is
compatible with Hibernate ORM 6.x.
Spanner Dialect produces SQL, DML, and DDL statements for most
common entity types and relationships using standard Hibernate and
Java Persistence annotations.
The service account JSON credentials
file location should be in the GOOGLE_APPLICATION_CREDENTIALS
environment variable. The driver will use default credentials set
in the Google Cloud CLI gcloud application otherwise.
Use Hibernate with Spanner GoogleSQL
For more information about the features and recommendations for
Hibernate, consult the
reference documentation
on GitHub.
What's next
Checkout code examples using Hibernate with
Spanner.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Integrate Spanner with Hibernate ORM (GoogleSQL dialect)\n\nHibernate is an object-relational mapping tool for the Java programming language.\nIt provides a framework for mapping an object-oriented domain model to a relational database.\n\nYou can integrate GoogleSQL-dialect databases with Hibernate using the open source\n[Spanner Dialect](https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate)\n(`SpannerDialect`). Spanner is\ncompatible with [Hibernate ORM 6.x](https://hibernate.org/orm/).\nSpanner Dialect produces SQL, DML, and DDL statements for most\ncommon entity types and relationships using standard Hibernate and\nJava Persistence annotations.\n\nSet up Hibernate\n----------------\n\nIn your project, add Apache Maven dependencies for Hibernate ORM core,\n[Spanner Dialect](https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate),\nand the Spanner officially supported\n[Open Source JDBC driver](/spanner/docs/use-oss-jdbc). \n\n \u003cdependencies\u003e\n \u003c!-- The Spanner JDBC driver dependency --\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003ecom.google.cloud\u003c/groupId\u003e\n \u003cartifactId\u003egoogle-cloud-spanner-jdbc\u003c/artifactId\u003e\n \u003c/dependency\u003e\n\n \u003c!-- Hibernate core dependency --\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003eorg.hibernate.orm\u003c/groupId\u003e\n \u003cartifactId\u003ehibernate-core\u003c/artifactId\u003e\n \u003cversion\u003e6.4.4.Final\u003c/version\u003e\n \u003c/dependency\u003e\n \u003c/dependencies\u003e\n\nConfigure `hibernate.cfg.xml` to use Spanner Dialect and\nSpanner JDBC Driver. \n\n \u003c!-- Connection settings --\u003e\n \u003cproperty name=\"hibernate.dialect\"\u003eorg.hibernate.dialect.SpannerDialect\u003c/property\u003e\n \u003cproperty name=\"hibernate.connection.driver_class\"\u003ecom.google.cloud.spanner.jdbc.JdbcDriver\u003c/property\u003e\n \u003cproperty name=\"hibernate.connection.url\"\u003ejdbc:cloudspanner:/projects/{YOUR_PROJECT_ID}/instances/{YOUR_INSTANCE_ID}/databases/{YOUR_DATABASE_ID}\u003c/property\u003e\n\nThe [service account JSON credentials](/docs/authentication/getting-started)\nfile location should be in the `GOOGLE_APPLICATION_CREDENTIALS`\nenvironment variable. The driver will use default credentials set\nin the Google Cloud CLI `gcloud` application otherwise.\n\nUse Hibernate with Spanner GoogleSQL\n------------------------------------\n\nFor more information about the features and recommendations for\nHibernate, consult the\n[reference documentation](https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate/blob/-/README.adoc)\non GitHub.\n\nWhat's next\n-----------\n\n- Checkout [code examples](https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate/blob/-/google-cloud-spanner-hibernate-samples) using Hibernate with Spanner.\n- Try the Spanner with Hibernate ORM [codelab](https://codelabs.developers.google.com/codelabs/cloud-spanner-hibernate).\n- Learn more about [Hibernate ORM](https://hibernate.org/orm/).\n- View the repository for [Spanner Dialect](https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate) on GitHub.\n- [File a GitHub issue](https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate/issues) to report a bug or ask a question about Hibernate.\n- Learn more about [Apache Maven](https://maven.apache.org/).\n- Learn more about [Integrate Spanner with Hibernate ORM (PostgreSQL dialect)](/spanner/docs/use-hibernate-postgresql)."]]