I fear, I could not find anything helpful googling, for the following issue.
in my Spring Boot (3.3.3) app the table creation in MariaDB (Docker, mariadb:11.2.2-jammy) fails for the following entity:
@Entity
public final class Answer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotNull
@Column(columnDefinition="LONGTEXT")
private String text;
}
Hibernate: create table `answer` (`id` bigint not null, `text` `LONGTEXT` not null, primary key (`id`)) engine=InnoDB
2024-09-19 23:59:21.367 [main] WARN o.m.jdbc.message.server.ErrorPacket : Error: 4161-HY000: Unknown data type: 'LONGTEXT'
2024-09-19 23:59:21.367 [main] WARN o.h.t.s.i.ExceptionHandlerLoggedImpl: GenerationTarget encountered exception accepting command : Error executing DDL "create table `answer` (`id` bigint not null, `text` `LONGTEXT` not null, primary key (`id`)) engine=InnoDB" via JDBC [(conn=415) Unknown data type: 'LONGTEXT']
The issue here is, that in the generated SQL code the LONGTEXT comes in quotes. I can manually run the code successful when removing the quotes. I don't understand why the quotes are there.
Any ideas?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope> <!-- for local development -->
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.4.1</version>
</dependency>
- SPRING_DATASOURCE_URL=jdbc:mariadb://mariadb:3306/${MYSQL_DATABASE}
- SPRING_DATASOURCE_DRIVER_CLASS_NAME=org.mariadb.jdbc.Driver
- SPRING_DATASOURCE_INITIALIZATION_MODE=always
- SPRING_H2_CONSOLE_ENABLED=false
- SPRING_JPA_HIBERNATE_DDL_AUTO=${SPRING_JPA_HIBERNATE_DDL_AUTO}
- SPRING_JPA_SHOW_SQL=true
- SPRING_JPA_DATABASE_PLATFORM=org.hibernate.dialect.MariaDBDialect
MYSQL_DATABASE=redacted
SPRING_JPA_HIBERNATE_DDL_AUTO=create
SPRING_H2_CONSOLE_ENABLED=false
The problem was self-made. I overlooked this config line in a run configuration.
spring.jpa.properties.hibernate.globally_quoted_identifiers
If I understand this post correctly, if you would need the property you could avoid my issue with the quote-keeping by adding:
spring.jpa.properties.hibernate.globally_quoted_identifiers_skip_column_definitions=true