hibernategoogle-cloud-platformormgoogle-cloud-spannerspring-cloud-gcp

Spring Boot 3 + Hibernate 6 migration: GCP Spanner Dialect latest v1.6.0 still refers to old ORM hibernate core


I'm in the process of upgrading a Spring Boot 2.7.7 + Hibernate 5 application to Spring Boot 3 and Hibernate 6. While updating I noticed that spring cloud spanner dialect latest v1.6.0 still refers to older hibernate package structure and coz of that getting as mentioned below and issue.

In Hibernate 6, As explained here this might be related to the new way of updating package structure for hibernate-core jar. This dependency needs to be updated to refer latest hibernate-core jar which recently moved to "org.hibernate.orm"

https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate/blob/230de173f5035a1f50072cbad88ef3e7117347f5/google-cloud-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/SpannerServiceContributor.java#L30

Spanner Dialect referring to old hibernate core

1

Hibernate core updates

2

I tried changing the dependencies manually to refer older hibernate-core however there is no luck. As you all may there are significant changes spring boot 3 brings in so had to fix this on priority as spring-web has critical vulnerability. Git Issue: https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate/issues/556#issue-1592718169

ERROR SpringApplication Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: org/hibernate/tool/hbm2ddl/UniqueConstraintSchemaUpdateStrategy

Caused by: java.lang.NoClassDefFoundError: org/hibernate/tool/hbm2ddl/UniqueConstraintSchemaUpdateStrategy at com.google.cloud.spanner.hibernate.SpannerServiceContributor.contribute(SpannerServiceContributor.java:69)

Is there any workaround to fix this issue? or who can help form spanner hibernate dialect updates?


Solution

  • The Cloud Spanner Hibernate dialect in this repository only supports Hibernate 5.4.

    Hibernate 6.x comes with the Spanner dialect built-in: https://github.com/hibernate/hibernate-orm/blob/main/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java

    So the following should work:

    1. Remove the dependency on google-cloud-spanner-hibernate-dialect from your project.
    2. Update your dependencies to add Hibernate 6.x. This comes with the SpannerDialect built-in.
    3. Make sure that you also have a dependency declaration for google-cloud-spanner-jdbc.
    4. Update your configuration so it uses org.hibernate.dialect.SpannerDialect. This is the fully qualified class name of the built-in Spanner dialect in Hibernate 6.x.