spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
2.98k stars 1.41k forks source link

Error executing DDL #3435

Closed guillemc23 closed 5 months ago

guillemc23 commented 5 months ago

Hello everyone! πŸ‘‹πŸ»

I have encountered the following error on startup of my SpringBoot 3 application:

04-18 17:12:47,139 WARN  [main] org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl: HHH90000025: PostgreSQLDialect does not need to be specified explicitly using 'hibernate.dialect' (remove the property setting and it will be selected by default)
2024-04-18 17:12:53,541 INFO  [main] org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator: HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
2024-04-18 17:12:53,817 WARN  [main] org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl: GenerationTarget encountered exception accepting command : Error executing DDL "alter table if exists purchase alter column amount set data type int default 5" via JDBC [ERROR: syntax error at or near "default"
  Position: 67]
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table if exists purchase alter column amount set data type int default 5" via JDBC [ERROR: syntax error at or near "default"
  Position: 67]

I want the default value of my new column to be 5, so I'm setting columnDefiniton as:

@Column(name = "amount", columnDefinition = "integer default 5", nullable = false)
private Integer amount;

This translates into an invalid SQL query as the following:

alter table if exists purchase alter column amount set data type int default 5

I have tried executing this exact same query using DBeaver on my PostgreSQL database and I'm getting the same error as hibernate above.

I'm not sure what to do, if anybody can point me in the right direction it would be amazing!

christophstrobl commented 5 months ago

Thanks for getting in touch. This is a Hibernate problem that would be better asked on Stack Overflow or be reported to the hibernate team. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug in this project.

quaff commented 5 months ago

I reported it by https://hibernate.atlassian.net/browse/HHH-18004, It should be fixed by https://github.com/hibernate/hibernate-orm/pull/8137.

guillemc23 commented 5 months ago

Nice one @quaff, hope it gets merged soon πŸ˜„