Integrare Spanner con Spring Data JPA (dialetto GoogleSQL)
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Spring Data JPA, che fa parte della più grande famiglia Spring Data, semplifica l'implementazione di repository basati su JPA. Spring Data JPA supporta Spanner e una vasta gamma di altri sistemi di database. Aggiunge un livello di astrazione tra
la tua applicazione e il tuo database che semplifica il porting
da un sistema di database a un altro.
Configurare Spring Data JPA per i database con dialetto GoogleSQL di Spanner
Puoi integrare i database con il dialetto GoogleSQL di Spanner con Spring Data JPA utilizzando il dialetto Hibernate Spanner (SpannerDialect) open source.
[[["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 Spring Data JPA (GoogleSQL dialect)\n\nSpring Data JPA, part of the larger Spring Data family, makes it\neasier to implement JPA based repositories. Spring Data JPA\nsupports Spanner\nand a wide range of other database systems. It adds an abstraction layer between\nyour application and your database that makes your application easier to port\nfrom one database system to another.\n\nSet up Spring Data JPA for Spanner GoogleSQL-dialect databases\n--------------------------------------------------------------\n\nYou can integrate Spanner GoogleSQL-dialect databases with Spring Data JPA using the\nopen source [Spanner Hibernate Dialect](https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate)\n(`SpannerDialect`).\n\nTo see an example, refer to the full\n[working sample application](https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate/blob/-/google-cloud-spanner-hibernate-samples/spring-data-jpa-full-sample) on\nGitHub.\n\n### Dependencies\n\nIn your project, add Apache Maven dependencies for [Spring Data JPA](https://spring.io/projects/spring-data-jpa),\n[Spanner Hibernate Dialect](https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate),\nand the Spanner officially supported [Open Source JDBC driver](/spanner/docs/use-oss-jdbc). \n\n \u003cdependencies\u003e\n \u003c!-- Spring Data JPA --\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n \u003cartifactId\u003espring-boot-starter-data-jpa\u003c/artifactId\u003e\n \u003c/dependency\u003e\n \u003c!-- Hibernate Dialect and JDBC Driver dependencies--\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003ecom.google.cloud\u003c/groupId\u003e\n \u003cartifactId\u003egoogle-cloud-spanner-hibernate-dialect\u003c/artifactId\u003e\n \u003c/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 \u003c/dependencies\u003e\n\n### Configuration\n\nConfigure `application.properties` to use the Spanner Hibernate\nDialect and the Spanner JDBC Driver. \n\n # Spanner connection URL.\n # - ${PROJECT_ID} Replace with your GCP project ID\n # - ${INSTANCE_ID} Replace with your Spanner instance ID\n # - ${DATABASE_NAME} Replace with the name of your Spanner database that you created inside your Spanner instance\n\n spring.datasource.url=jdbc:cloudspanner:/projects/${PROJECT_ID}/instances/${INSTANCE_ID}/databases/${DATABASE_NAME}\n\n # Specify the Spanner JDBC driver.\n spring.datasource.driver-class-name=com.google.cloud.spanner.jdbc.JdbcDriver\n\n # Specify the Spanner Hibernate dialect.\n spring.jpa.properties.hibernate.dialect=com.google.cloud.spanner.hibernate.SpannerDialect\n\n spring.jpa.hibernate.ddl-auto=update\n\n # Settings to enable batching statements for efficiency\n spring.jpa.properties.hibernate.jdbc.batch_size=100\n spring.jpa.properties.hibernate.order_inserts=true\n\n # You can display SQL statements and stats for debugging if needed.\n spring.jpa.properties.hibernate.show_sql=true\n spring.jpa.properties.hibernate.format_sql=true\n\nFull Sample Application\n-----------------------\n\nA [working sample application](https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate/blob/-/google-cloud-spanner-hibernate-samples/spring-data-jpa-full-sample) is\navailable on GitHub.\n\nWhat's next\n-----------\n\n- Learn more about [Spring Data JPA](https://spring.io/projects/spring-data-jpa).\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- [Integrate Spanner with Spring Data JPA (PostgreSQL dialect)](/spanner/docs/use-spring-data-jpa-postgresql)."]]