h2 が一部の mysql 8.0 クエリの実行に失敗する
温馨提示:
本文最后更新于 2024年04月12日,已超过 37 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我。
h2 を使用して SQL ステートメントを実行するとエラーが返される
CREATE TRIGGER _afterUserCreate BEFORE INSERT ON "user" FOR EACH ROW INSERT INTO claimingcoins (userid, claiming_coins) VALUES (NEW.id, 0)
そして
INSERT INTO leaderboard VALUES (UUID_TO_BIN(UUID(), true), "TR", 100, 10, 5, 100)
エラーは次のとおりです
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE TRIGGER _afterUserCreate BEFORE INSERT ON ""user"" FOR EACH ROW [*]INSERT INTO claimingcoins (userid, claiming_coins) VALUES (NEW.id, 0)"; expected "QUEUE, NOWAIT, AS, CALL"; SQL statement:
そして
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Function "UUID_TO_BIN" not found; SQL statement:INSERT INTO leaderboard VALUES (UUID_TO_BIN(UUID(), true), "TR", 100, 10, 5, 100)
最初のエラーについては、h2がTRIGGER
まだ認識していないため、これには回避策があるはずだと思います。
2番目のエラーについては、h2を使用してUUIDを生成する方法がある場合はbinary(16)
、それを使用することもできます。
必要な場合に備えて、これが私のものapplication.properties
ファイルです。
spring.datasource.url=jdbc:h2:mem:test;MODE=MySQL;
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=
spring.datasource.password=
# We add the MySQL Dialect so that it understands and generates the query based on MySQL
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
#spring.sql.init.data-locations=data-test.sql
spring.h2.console.enabled=true
spring.jpa.defer-datasource-initialization=true
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
#spring.sql.init.mode=always
注:"user"
次の理由から、二重引用符を使用します。
https://www.baeldung.com/spring-boot-h2-jdbcsqlsyntaxerrorException-expected-identifier
.sql ファイル内で実行させるための代替ステートメントは何でしょうか?
正文到此结束
- 本文标签: 家庭宠物
- 本文链接: https://www.coder6.net/article/2632
- 版权声明: 本文由蚂蚁原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权