Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Spring and the fly likes Weird implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Weird implementation" Watch "Weird implementation" New topic

Weird implementation

Sripathi Krishnamurthy
Ranch Hand

Joined: Mar 07, 2005
Posts: 232
I noticed a strange implementation in Spring 2.5.6 JDBC jar..

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 your comments/suggestions.
It is sorta covered in the JavaRanch Style Guide.
subject: Weird implementation