Integrare Spanner con Hibernate ORM (dialetto GoogleSQL)
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Hibernate è uno strumento di mappatura relazionale degli oggetti per il linguaggio di programmazione Java.
Fornisce un framework per mappare un modello di dominio orientato agli oggetti a un database relazionale.
Puoi integrare i database con dialetto GoogleSQL con Hibernate utilizzando Spanner Dialect (SpannerDialect) open source. Spanner è compatibile con Hibernate ORM 6.x.
Spanner Dialect produce istruzioni SQL, DML e DDL per la maggior parte dei tipi di entità e delle relazioni più comuni utilizzando le annotazioni Hibernate e Java Persistence standard.
Configurare Hibernate
Nel tuo progetto, aggiungi le dipendenze di Apache Maven per Hibernate ORM core, Spanner Dialect e il driver JDBC open source supportato ufficialmente da Spanner.
La posizione del file delle credenziali JSON del service account
deve essere nella variabile di ambiente GOOGLE_APPLICATION_CREDENTIALS. In caso contrario, il driver utilizzerà le credenziali predefinite impostate
nell'applicazione Google Cloud CLI gcloud.
Utilizzare Hibernate con Spanner GoogleSQL
Per saperne di più sulle funzionalità e sui consigli per
Hibernate, consulta la
documentazione di riferimento
su GitHub.
Passaggi successivi
Consulta gli esempi di codice di pagamento che utilizzano Hibernate con
Spanner.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-05 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)."]]