Giter Club home page Giter Club logo

Comments (7)

wilkinsona avatar wilkinsona commented on July 19, 2024 2

Thanks for the sample, I've reproduced the problem and observed that it does not occur when downgrading Hibernate to 6.4.8.Final:

ext['hibernate.version'] = "6.4.8.Final"

This tells us that the change in behavior is due to a change in Hibernate 6.5.

The SQL dialect for Postgres is generating different SQL and this SQL is now incompatible with H2 running in Postgres compatibility mode.

With Hibernate 6.5, the SQL is the following:

insert into report_config (period_type) values (?) returning id

With Hibernate 6.4, it's the following:

insert into report_config (period_type) values (?)

If it works fine with a real Postgres instance then this is arguably a bug in/limitation of H2's Postgres compatibility mode that Hibernate's changed SQL is triggering. If it doesn't work with a real Postgres instance then I think it's a Hibernate bug.

Either way, I'm afraid that this is out of Spring Boot's control and will have to be dealt with by the maintainers of Hibernate or of H2.

from spring-boot.

quaff avatar quaff commented on July 19, 2024 1

@quaff Indeed I'm using another dialect, as in production there's a postgresql database and I need it to be as close to this as possible. With Spring Boot 3.2.6 everything was fine. I followed the migration guide for Hibernate 6.5 but both resolutions found there still produce the error mentioned above. I got there through the release notes link.

This is the minimal sample you've asked for @wilkinsona , thank you for your swift and clear response! https://github.com/Sax388/sql-h2-postgres-error-on-upgrade-to-spring-3.3.0

@Sax388 Why not let Hibernate choose the right dialect? IMO, you shouldn't specify dialect if the database is well-known.

from spring-boot.

quaff avatar quaff commented on July 19, 2024 1

@quaff Thank you for your support. I didn't quite get you. I intentionally chose to use

      driverClassName: org.h2.Driver
      url: jdbc:h2:mem:testdb;MODE=PostgreSQL;DEFAULT_NULL_ORDERING=HIGH;NON_KEYWORDS=VALUE

to make it behave more like the well-known database in production (there were some issues, not detected by the tests before). We're only using H2 for our tests. I think it's time to ditch it and move on to using a full postgresql database e.g. inside testcontainers. What do you think?

EDIT: I feel a little dumb now, but h2database/h2database#3962 (comment) told me there was a bad configuration right above the properties mentioned above. Without these it's actually working again.

Sorry, I thought you are manually set hibernate dialect, It's MODE=PostgreSQL in jdbc url make hibernate detect H2 as PostgreSQL, I would like suggest you use H2 for unit tests and introduce testcontainers to use real PostgreSQL in integration tests.

EDIT: you are manually set hibernate dialect indirectly by spring.jpa.database=postgresql, not caused by MODE=PostgreSQL.

from spring-boot.

wilkinsona avatar wilkinsona commented on July 19, 2024

I don't see the connection between the error that you're seeing and the question on Stack Overflow. The former is a problem reported by H2 when executing an SQL query. The latter is an error reported by Hibernate when parsing an HQL query.

If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

from spring-boot.

quaff avatar quaff commented on July 19, 2024

I believe you are using wrong hibernate dialect because H2Dialect will not generate unsupported sql like ... returning id.

from spring-boot.

Sax388 avatar Sax388 commented on July 19, 2024

@quaff Indeed I'm using another dialect, as in production there's a postgresql database and I need it to be as close to this as possible. With Spring Boot 3.2.6 everything was fine. I followed the migration guide for Hibernate 6.5 but both resolutions found there still produce the error mentioned above. I got there through the release notes link.

This is the minimal sample you've asked for @wilkinsona , thank you for your swift and clear response!
https://github.com/Sax388/sql-h2-postgres-error-on-upgrade-to-spring-3.3.0

from spring-boot.

Sax388 avatar Sax388 commented on July 19, 2024

@quaff Thank you for your support. I didn't quite get you. I intentionally chose to use

      driverClassName: org.h2.Driver
      url: jdbc:h2:mem:testdb;MODE=PostgreSQL;DEFAULT_NULL_ORDERING=HIGH;NON_KEYWORDS=VALUE

to make it behave more like the well-known database in production (there were some issues, not detected by the tests before). We're only using H2 for our tests. I think it's time to ditch it and move on to using a full postgresql database e.g. inside testcontainers. What do you think?

EDIT: I feel a little dumb now, but h2database/h2database#3962 (comment) told me there was a bad configuration right above the properties mentioned above. Without these it's actually working again.

from spring-boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.