0

I get the following error when initialising MySQL in docker

Caused by: java.sql.SQLSyntaxErrorException: Specified key was too long; max key length is 1000 bytes
spring-boot-jpa-docker-webapp_1  |  at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1  |  at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1  |  at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1  |  at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:782) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1  |  at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:666) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1  |  at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-jpa-docker-webapp_1  |  at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-jpa-docker-webapp_1  |  at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1  |  ... 40 common frames omitted

It actually failed to create the table

spring-boot-jpa-docker-webapp_1  | 2019-02-14 16:05:20.852  WARN 1 --- [           main] o.h.t.s.i.ExceptionHandlerLoggedImpl     : GenerationTarget encountered exception accepting command : Error executing DDL "create table reading (vin varchar(255) not null, check_engine_light_on bit not null, cruise_control_on bit not null, engine_coolant_low bit not null, engine_hp integer not null, engine_rpm integer not null, fuel_volume double precision not null, latitude double precision not null, longitude double precision not null, speed integer not null, timestamp datetime, front_left integer not null, front_right integer not null, rear_left integer not null, rear_right integer not null, primary key (vin)) engine=MyISAM" via JDBC Statement

Also, any alternative to MySQL, MariaDB? I am facing error with both.

The solutions available are for normal MySQL and not docker-compose version.

andolsi zied
  • 3,553
  • 2
  • 32
  • 43
A.Dev
  • 569
  • 1
  • 5
  • 19
  • 1
    Turn on sql statement logging in your Spring Boot app – Justin Tamblyn Feb 14 '19 at 16:12
  • @Just1689 Logging is on, one table is created the other table as shown in question is not. – A.Dev Feb 14 '19 at 16:16
  • Did you define an index on that table? If not, then the primary key is a long `VARCHAR`, so change the table to not use a `VARCHAR` as a primary key. – Andreas Feb 14 '19 at 16:21
  • @Andreas how can I do that? I define the structure in a class like private String vin; – A.Dev Feb 14 '19 at 16:23
  • 2
    It is common practice to make the primary key a number that is automatically assigned by the database. Perhaps you need to learn more about SQL databases before you continue. You can also search online for how to do primary keys with JPA, to learn more about that. – Andreas Feb 14 '19 at 16:25
  • Why are you trying to use such a large key? It is an order of magnitude too large for practical use. – user207421 Feb 14 '19 at 23:10
  • Fix, add this to application.yml: spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL55Dialect – André Mathisen Jan 28 '20 at 19:47

0 Answers0