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 PostgreSQL-dialect databases with Hibernate using the open source Spanner JDBC driver. Hibernate ORM 7.4 is supported with PostgreSQL-dialect databases.
Set up Hibernate with PostgreSQL
In your Google Cloud project, add Apache Maven dependencies for the Hibernate ORM core and Spanner JDBC driver.
org.hibernate.orm
hibernate-core
7.4.0.Final
com.google.cloud
google-cloud-spanner-jdbc
2.40.0
Set up Hibernate properties
Configure hibernate.properties to use the SpannerPostgreSQLDialect,
Spanner JDBC driver, and required connection properties in the URL.
hibernate.dialect=org.hibernate.dialect.SpannerPostgreSQLDialect
hibernate.connection.driver_class=com.google.cloud.spanner.jdbc.JdbcDriver
hibernate.connection.url=jdbc:cloudspanner:/projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID?defaultsequencekind=bit_reversed_positive
hibernate.show_sql=true
hibernate.format_sql=true
# hibernate.hbm2ddl.auto validate
hibernate.hbm2ddl.auto=update
Use Hibernate
For more information about the features and recommendations for integrating Hibernate with PostgreSQL-dialect databases, please consult the reference documentation on GitHub.
What's next
- Learn more about Spanner JDBC driver.
- Learn more about Hibernate ORM.
- For more information about Spanner JDBC driver connection options, see JDBC Connection Options in the Google Cloud Java GitHub repository.
- Learn more about Integrate Spanner with Hibernate ORM (GoogleSQL dialect).
- See an overview of drivers and ORMs supported for Spanner.