Announcement Announcement Module
No announcement yet.
Strange implementation in Spring JDBC Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Strange implementation in Spring JDBC

    I noticed a strange implementation in Spring 2.5.6 JDBC jar..
        In the bean,  
        public class SaveCartShoppingList {  
            private boolean transactionFlag = false;  
            public boolean isTransactionFlag() {  
                return transactionFlag;  
            public void setTransactionFlag(boolean transactionFlag) {  
                this.transactionFlag = transactionFlag;  
        DAO implementation is as below..  
        SimpleJdbcInsert insertShoppingList = new SimpleJdbcInsert(dataSource).withTableName(SaveCartDao.SHOPPING_LIST).usingColumns("sc_shopping_list_id", "service_zipcode", "email_id", "transaction_flag");  
        SqlParameterSource parameters = new MapSqlParameterSource().addValue(SaveCartDao.SHOPPING_LIST_ID, shoppingListId).addValue(SaveCartDao.SERVICE_ZIPCODE, ssl.getServiceZipcode()).addValue(SaveCartDao.EMAIL, ssl.getScEmailAddress().toUpperCase()).addValue(SaveCartDao.TRANSACTION_FLAG, ssl.isTransactionFlag());  
        int insertRows = insertShoppingList.execute(parameters);
    The underlying table has a column called TRANSACTION_FLAG which is varchar(1). So it takes only 1 char of data. But as you can see from the above code, transaction flag is a boolean.
    But surprisingly, the above code worked perfectly fine in Spring 2.5.6. When run, it used to insert 0 or 1, based on the flag. How did this happen? How did Spring 2.5.6 automatically convert a boolean to 0 or 1? Did it read the column metadata and convert a boolean to fit in the column size? What if I needed a Y or N instead of 0 or 1?

    When I upgraded to Spring 3.1.0 JDBC jar, the same logic failed. It gives the error column data too long for the column. I think this error is correct. Spring should not automatically convert anything from boolean to whatever it likes by reading column metadata.

    Was it a bug in spring 2.5.6 JDBC which was fixed in 3.1.0 JDBC?

    Please let me know .