我已经设置了以下POJO:
@Getter
@Setter
@AllArgsConstructor
@Entity
@Table(name = "SpreadsheetRequest")
public class SpreadsheetRequest {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(updatable = false, nullable = false, unique = true)
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private Integer id;
private String spreadsheetId;
private String name;
private String range;
@SuppressWarnings("unused")
public SpreadsheetRequest() {
setSpreadsheetId(null);
setName(null);
setRange(null);
}
}
并按如下所示配置我的环境:
spring.h2.console.enabled=true
spring.h2.console.path=/h2
spring.datasource.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.initialization-mode=embedded
spring.jpa.properties.hibernate.hbm2ddl.import_files=classpath://resources/import.sql
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
import.sql
看起来像这样:
INSERT INTO SPREADSHEET_REQUEST VALUES ('DYsErzRPCLEoYYzQkemEAeerYiQ3Usyn','Test','Sheet1!A1:A12');
我在加载时不断遇到以下错误:
Caused by: org.h2.jdbc.JdbcSQLException: Column count does not match; SQL statement:
INSERT INTO SPREADSHEET_REQUEST VALUES ('DYsErzRPCLEoYYzQkemEAeerYiQ3Usyn','Test','Sheet1!A1:A12') [21002-197]
是什么原因造成的?
答案 0 :(得分:2)
原因是
列数不匹配
您尝试插入3列,而您的实体(因此db中的表也是如此)有4列。在查询中包含id
:
INSERT INTO SPREADSHEET_REQUEST VALUES (1, 'DYsErzRPCLEoYYzQkemEAeerYiQ3Usyn','Test','Sheet1!A1:A12');