Integrate Spanner with Hibernate ORM (PostgreSQL dialect)

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 sourcePostgreSQL JDBC Driver.Hibernate ORM 6.3is supported with PostgreSQL-dialect databases.

Set up PGAdapter

Ensure that PGAdapter is running on the same machine as the application that isusing Hibernate.

For more information, seeStart PGAdapter.

Set up Hibernate with PostgreSQL

In your project, add Apache Maven dependencies for the Hibernate ORM core and PostgreSQL JDBC Driver.

<!-- Hibernate core dependency --><dependency>  <groupId>org.hibernate.orm</groupId>  <artifactId>hibernate-core</artifactId>  <version>6.3.1.Final</version></dependency><!-- Postgresql JDBC driver dependency --><dependency>  <groupId>org.postgresql</groupId>  <artifactId>postgresql</artifactId>  <version>42.7.1</version></dependency>

Set up Hibernate properties

Configurehibernate.properties to use the PostgreSQL dialect andPostgreSQL JDBC Driver.

hibernate.dialect=org.hibernate.dialect.PostgreSQLDialecthibernate.connection.driver_class=org.postgresql.Driverhibernate.connection.url=jdbc:postgresql://localhost:5432/test-databasehibernate.connection.username=pratickhibernate.connection.pool_size=5hibernate.show_sql=truehibernate.format_sql=true# hibernate.hbm2ddl.auto validatehibernate.hbm2ddl.auto=update

Use Hibernate

For more information about the features and recommendations for integratingHibernate with PostgreSQL-dialect databases, please consult thereference documentationon GitHub.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-17 UTC.