我尝试在我的 spring 应用程序中运行以下测试。
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=App1Application.class)
@Sql(scripts="customerTest.sql")
@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
public class customerTest {
@Autowired
customerRepository customerDB;
@Test
public void countRecords(){
assertThat(customerDB.count(),is(2l));
}
}
在 customerTest.sql 文件中我有:
insert into customer(id,name,lastname) values(1,"name","lastname");
这是我的客户类
@Entity
@Data
public class customer {
@Id
@GeneratedValue
int id;
String name;
String lastname;
}
我也使用jpa:
public interface customerRepository extends JpaRepository<customer,Long>{
}
问题是,当我运行测试时遇到错误:
org.h2.jdbc.JdbcSQLException: Column "Salman" not found; SQL statement:
insert into customer(id,name,lastname) values(1,"name","lastname")
同时“Salman”是一个值而不是一列?
请注意,我正在使用 spring-mvc,所以没有没有数据库
我只有代码制作的模型(客户
)。
最佳答案
编译器产生这种错误的行为对我来说仍然是一个问题,
但我设法使用这个单引号 ''
而不是双引号 ""
我用这个
insert into customer(id,name,lastname) values(1,'name','Lastname')
而不是
insert into customer(id,name,lastname) values(1,"name","Lastname")
关于java - org.h2.jdbc.JdbcSQL异常 : Column "Salman" not found;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35646432/