Hibernate 嵌套异常是org.h2.jdbc.JdbcSQLException:Column";评论「;未找到;SQL语句:

Hibernate 嵌套异常是org.h2.jdbc.JdbcSQLException:Column";评论「;未找到;SQL语句:,hibernate,spring-data-jpa,h2,Hibernate,Spring Data Jpa,H2,使用H2数据库运行JPA存储库的spring引导测试用例 在H2数据库的data.sql文件中,我尝试使用列名作为“COMMENT”,并且COMMENT仍然得到相同的异常。我的存储库扩展了分页和排序存储库 例外情况 Caused by: org.h2.jdbc.JdbcSQLException: Column "COMMENT" not found; SQL statement:INSERT INTO RESEARCH_REQUEST (ID, MOD_COUNT, CLIENT_NAME, "

使用H2数据库运行JPA存储库的spring引导测试用例

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

例外情况

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;
主要应用程序属性

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
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
测试应用程序.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
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 {
在代码中,您提供的@column注释的名称和名称不需要使用[]

试试这个:

@Column(name = "COMMENT", length = 1000)
私有字符串注释


另外,请检查数据库表中的字段名,并在查询中提供相同的字段名。

很抱歉,回复太晚,尝试了上述方法,测试用例通过,应用程序启动良好,但是当我测试应用程序时(尝试在oracle表中插入一行)无法在oracle表中插入记录。所述代码仅用于在db中创建新列。您可能在保存数据的代码中出错。如果答案对您有帮助,请接受答案并投票表决。谢谢