Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.h2.jdbc.JdbcSQLException: Column "Salman" not found;

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.

like image 710
Sal-laS Avatar asked Feb 26 '16 08:02

Sal-laS


1 Answers

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")
like image 67
Sal-laS Avatar answered Nov 08 '22 23:11

Sal-laS