Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H2 (version 2.0.202 ) auto_increment not working #3302

Closed
juniormichieletto opened this issue Dec 23, 2021 · 2 comments
Closed

H2 (version 2.0.202 ) auto_increment not working #3302

juniormichieletto opened this issue Dec 23, 2021 · 2 comments

Comments

@juniormichieletto
Copy link

juniormichieletto commented Dec 23, 2021

Hello :)

We are trying to bump the h2 dependency from 1.4.200 to 2.0.202 and the auto increment is not working anymore in my spring application.

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>2.0.202</version>
    <scope>test</scope>
</dependency>
spring:
  datasource:
    url: "jdbc:h2:mem:testdb;MODE=MYSQL"
    driverClassName: "org.h2.Driver"
    username: "sa"
    password: "password"

And we are using the GenerationType.IDENTITY as strategy in our model:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)

Ps. I've tried with MYSQL compatibility and without compatibility mode as well with the same result.

Thank you in advance

I also found a simillar question on stack overflow, see:
https://stackoverflow.com/questions/70453996/h2-version-2-0-202-auto-increment-not-working

And I found the following issue fixed in the previous release changelog:
https://h2database.com/html/changelog.html
Issue #1913: MySQL: auto_increment changing SQL not supported

@katzyn
Copy link
Contributor

katzyn commented Dec 23, 2021

Question from SO is completely unrelated. It is about Oracle compatibility mode where AUTO_INCREMENT should not work, because it doesn't work in Oracle.

Issue #1913 is about exotic DDL command that most likely isn't used by Hibernate.

Hibernate ORM doesn't support H2 2.0 yet, but it may work with H2 2.0.4 when some compatibility settings like ;MODE=LEGACY and possibly others are in use, it depends on features used by application.

In the default Regular mode H2 2.0 works like normal standard-compliant databases and rejects, for example, attempts to insert a NULL value into column with NOT NULL constraint, but Hibernate tries to do that, see issue HHH-14985.

General issue about support of H2 2.0 in Hibernate ORM is here: HHH-14180.

On the other hand, MySQL compatibility mode wasn't changed in H2 2.0 in any significant way. Various MySQL-compatible operations and features still work in this mode, but you really should use H2 2.0.4, because there were some problems in 2.0.202. And what exactly do you mean by “not working”? Do you see some exception or what? You need to provide more details.

@juniormichieletto
Copy link
Author

I see, then I'll wait for Hibernate issue be fixed.
Thank you for the explanation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants