On 8/16/2012 11:19 AM, Stephen Friedrich wrote:
> When I read an object the natural assumption is that it holds exactly
> the values returned from the mapped statement.
> When the object has primitive fields, but null is returned from the db,
> then a natural way to handle it would be to throw an exception. It's
> clearly a programmer error to use a primitive field for a nullable column.
I don't agree with the last statement. One of the strong points of
MyBatis (the reason we adopted it) was it functions well in the presence
of "impedance" mismatch. We have many legacy databases that are not
well normalized and missing a lot of referential integrity checks.
MyBatis continues to provide a useful mapping in this environment, while
a more strict solution like Hibernate would simply not work.
Having said all that, you obviously can't stuff a null into an int. So,
the problem is not using a primitive field for a nullable column, but
failing to account for it in the SQL.
--
Guy Rouillier