[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-05。"],[],[],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)."]]