嵌套的异常是org.h2.jdbc.JdbcSQLException:找不到列“ COMMENT”。 SQL语句:

时间:2019-05-10 07:05:04

标签: hibernate spring-data-jpa h2

运行带有H2数据库的JPA存储库的spring boot测试用例。

在H2数据库的data.sql文件中,我尝试使用列名作为“ COMMENT”,并且COMMENT仍然遇到相同的异常。我的存储库扩展了PagingAndSortingRepository。

例外

Caused by: org.h2.jdbc.JdbcSQLException: Column "COMMENT" not found; SQL statement:INSERT INTO RESEARCH_REQUEST (ID, MOD_COUNT, CLIENT_NAME, "COMMENT", PROCESS_ID, INITIATED_BY, INITIATED_AT, STATUS_CD, CREATOR, CREATE_TS) VALUES (500,0, 'Test Client','Test comment', 987654, 'test6@test.com', TO_TIMESTAMP('2018-12-19 12:03:21.000000000', 'YYYY-MM-DD HH24:MI:SS.FF'), 'A', 'test6@test.com', TO_TIMESTAMP('2018-12-19 12:03:21.000000000', 'YYYY-MM-DD HH24:MI:SS.FF')) [42122-197]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:357)
    at org.h2.message.DbException.get(DbException.java:179)
    at org.h2.message.DbException.get(DbException.java:155)
    at org.h2.table.Table.getColumn(Table.java:682)
    at org.h2.command.Parser.parseColumn(Parser.java:936)
    at org.h2.command.Parser.parseColumnList(Parser.java:920)
    at org.h2.command.Parser.parseInsertGivenTable(Parser.java:1258)
    at org.h2.command.Parser.parseInsert(Parser.java:1222)
    at org.h2.command.Parser.parsePrepared(Parser.java:431)
    at org.h2.command.Parser.parse(Parser.java:335)
    at org.h2.command.Parser.parse(Parser.java:307)
    at org.h2.command.Parser.prepareCommand(Parser.java:278)
    at org.h2.engine.Session.prepareLocal(Session.java:611)
    at org.h2.engine.Session.prepareCommand(Session.java:549)
    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1247)
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:217)
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:205)
    at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95)
    at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
    at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:473)

data.sql

INSERT INTO RESEARCH_REQUEST (ID, MOD_COUNT, CLIENT_NAME, "COMMENT", PROCESS_ID, INITIATED_BY, INITIATED_AT, STATUS_CD, CREATOR, CREATE_TS) VALUES (500,0, 'Test Client','Test comment', 987654, 'test6@test.com', TO_TIMESTAMP('2018-12-19 12:03:21.000000000', 'YYYY-MM-DD HH24:MI:SS.FF'), 'A', 'test6@test.com', TO_TIMESTAMP('2018-12-19 12:03:21.000000000', 'YYYY-MM-DD HH24:MI:SS.FF'));

实体类

@Column(name = "[COMMENT]", length = 1000)
private String comment;

主要application.properties

spring.datasource.url= jdbc:oracle:thin:@xxx.xx.xx.com:xxxx:xxxxx
spring.datasource.driverClassName= oracle.jdbc.driver.OracleDriver
spring.datasource.type= com.zaxxer.hikari.HikariDataSource
spring.datasource.maximumPoolSize=2
spring.datasource.maxLifeTime=300000
spring.datasource.minimumIdle=1
spring.datasource.idleTimeout=300000
spring.datasource.connectionTimeout=10000
spring.datasource.poolName=xxx-pool

测试application.properties

spring.datasource.url= jdbc:h2:mem:test;Mode=Oracle;DB_CLOSE_DELAY=-1
spring.datasource.driverClassName= org.h2.Driver
spring.datasource.type= com.zaxxer.hikari.HikariDataSource
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.initializationFailTimeout=1000
spring.datasource.connectionTimeout=30000
spring.datasource.maximumPoolSize=1
spring.datasource.maxLifetime=300000
spring.datasource.poolName=xxx-pool

测试类

@RunWith(SpringRunner.class)
@SpringBootTest(classes =XXXMicroserviceLauncher.class)
public class ResearchRequestRepositoryTest {

1 个答案:

答案 0 :(得分:0)

@Column(name =“ [COMMENT]”,长度= 1000)

私有字符串注释;

在您的代码中,您将为@column注释提供名称,并且无需使用[]。

尝试一下:

@Column(名称=“ COMMENT”,长度= 1000)

私有字符串注释;

还要检查数据库表中的字段名称,并在查询中提供相同的名称。