【发布时间】:2019-07-04 17:55:34
【问题描述】:
我想在springboot中通过H2创建表,但是运行时出现以下错误;
org.hibernate.dialect.Dialect:HHH000400:使用方言: org.hibernate.dialect.H2方言 org.hibernate.tool.schema.spi.CommandAcceptanceException:执行 DDL 时出错“创建表 bank_account(id bigint 不为空,余额 双非空,全名 varchar(128) 非空,主键 (id))" 通过 JDBC 语句
...
data.sql:
Insert into Bank_Account(ID, Full_Name, Balance) values (1, 'Ibrahim', 2500);
Insert into Bank_Account(ID, Full_Name, Balance) values (2, 'Ates', 4210);
pom.xml;
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
Application.properties;
# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2
# Datasource
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.datasource.continue-on-error=true
spring.jpa.hibernate.ddl-auto=create
我错过了什么?
解决方案;
问题是由实体的列名引起的。我已将名为“Full Name”的实体更改为“Full_Name”,然后问题就解决了。
【问题讨论】:
-
从你的 application.propeties 文件中显示你的休眠、数据库属性
-
我添加了问题的结尾...
-
好的,有映射到 Bank_Account 表的实体吗?如果是则显示
-
是的。就像跟随我一样; @Entity @Table(name="Bank_Account") 公共类 BankAccount { ... }
标签: java hibernate spring-boot orm h2