spring-boot-data-jpa在使用h2数据库时创建user表失败的原因
使用spring-boot-data-jpa操作h2数据库时,试图创建名为user的表时失败的原因是user是h2数据库的关键字。
根据h2官方文档,user是不能用作标识符(表名、列名)的关键字,除非用引号将其括起来。
要解决这个问题,有几种方法:
create table "user" ...
@entity @table(name = "\"user\"") publicclass user { ... }
hibernate.globally_quoted_identifiers=true
spring.jpa.properties.hibernate.auto_quote_keyword=true
CREATE TABLE `User` ...
解决方法应根据具体情况而选择。仔细检查代码中的配置和属性,以确保h2数据库可以正确处理user表。