H2 database with SpringBoot test -nested exception is org.h2.jdbc.JdbcSQLException: Column “COMMENT” not found; SQL statement:
I am new to springboot and hibernate, I was asked to rename spring.datasource.jdbcurl to spring.datasource.url present in application.properties(for both main classes and test classes) and remove existing configuration class(marked with @EnableJpaRepositories) which provides dataSource, entityManagerFactory and transactionFactory object. Made the changes but got struck with the below error.
In data.sql file for H2 database I have tried with column name as "COMMENT" and also with COMMENT still getting the same exception. My repository extends PagingAndSortingRepository.
Exception
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, '[email protected]', TO_TIMESTAMP('2018-12-19 12:03:21.000000000', 'YYYY-MM-DD HH24:MI:SS.FF'), 'A', '[email protected]', 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, '[email protected]', TO_TIMESTAMP('2018-12-19 12:03:21.000000000', 'YYYY-MM-DD HH24:MI:SS.FF'), 'A', '[email protected]', TO_TIMESTAMP('2018-12-19 12:03:21.000000000', 'YYYY-MM-DD HH24:MI:SS.FF'));
Entity class
@Column(name = "[COMMENT]", length = 1000)
private String comment;
main 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
test 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
Test class
@RunWith(SpringRunner.class)
@SpringBootTest(classes =XXXMicroserviceLauncher.class)
public class ResearchRequestRepositoryTest {
Is that column you added after creating the database, is it present in the h2 table?
Yes added the column in orcale database with table creation and yes the column is present in h2 table as well.