namedJdbcTemplate.update not working for list of string

144 Views Asked by At

I am trying to use named jdbctemplate.update to fire a delete query but somehow this query is not working.

This is my code

Order looks something like this

public class Order {
  private Long cuId;
  private String supplierType;
  private String customerType;
  private String orderType;
}

final List<Order> ordersStuckInNewStatus; //defined like this


//main code starts here

List<String> cuIds=
      ordersStuckInNewStatus.stream()
          .map(Order::getCuId)
          .map(id -> String.format("'%s'", id))
          .collect(Collectors.toList());
         
 syso(cuIds)      //Output:- ['193111000000000451']


  SqlParameterSource parameters = new MapSqlParameterSource("cuIds", cuIds);      
  
syso(parameters )      //Output:- MapSqlParameterSource {cuIds=['193111000000000451']}


  int deleteCount = 0;
  String sql = "DELETE FROM OLCM.REJECTED_EVENT where entity_id IN (:cuIds)";
  deleteCount = namedJdbcTemplate.update(sql, parameters);
  
  log.info("Delete Count:[{}]", deleteCount);
  

This is how many logs gets printed . No compilation error

Query:["DELETE FROM OLCM.REJECTED_EVENT where entity_id IN (?)"], Params:[('193111000000000451')]
Delete Count:[0]

Even though the correct query gets fired but somehow the reords did not get deleted. The records do exists in db.

Note:

  • entity_id is varchar

  • Instead of List<String> cuid if i use the below code it works

    List<Long> cuIds=ordersStuckInNewStatus.stream().map(Order::getCuId).collect(Collectors.toList());

Any reason why this is not working for List<String> but works for List<Long>

0

There are 0 best solutions below