I have tried to run the following test in my spring application.
@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));
}
}
and in the customerTest.sql file i have:
insert into customer(id,name,lastname) values(1,"name","lastname");
here is my customer class
@Entity
@Data
public class customer {
@Id
@GeneratedValue
int id;
String name;
String lastname;
}
and i use jpa too:
public interface customerRepository extends JpaRepository<customer,Long>{
}
The problem is, when i run the test i face with the error:
org.h2.jdbc.JdbcSQLException: Column "Salman" not found; SQL statement:
insert into customer(id,name,lastname) values(1,"name","lastname")
Meanwhile "Salman" is a value and not a column?
Please pay attention, i am using spring-mvc so there is no Database
I have only my models (customer
) made by code.
The behavior of compiler to make such an error is still a question for me,
but I managed to handle this error using this single quote ''
rather than double quote ""
I use this
insert into customer(id,name,lastname) values(1,'name','Lastname')
rather than
insert into customer(id,name,lastname) values(1,"name","Lastname")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With