BaseTypeHandler getResult(ResultSet rs, String columnName) possible bug.

11 views
Skip to first unread message

Graeme Knight

unread,
Jun 10, 2019, 12:11:35 PM6/10/19
to mybatis-user
Hi folks,

I recently started using MyBatis and love it compared to the popular ORMs out there! What a breath of fresh air and I so appreciate the work the contributors have put in!

It just took me a long while to debug a TypeHandler that I have written for work in some legacy code. I found the problem affecting me in BaseTypeHandler:

 @Override
 public T getResult(ResultSet rs, String columnName) throws SQLException {
   T result;
   try {
     result = getNullableResult(rs, columnName);
   } catch (Exception e) {
     throw new ResultMapException("Error attempting to get column '" + columnName + "' from result set.  Cause: " + e, e);
   }
   if (rs.wasNull()) {
     return null;
   } else {
     return result;
   }
 }

My TypeHandler DOES trigger rs.wasNull() but also returns a type that it has to get back to the caller. In my mind checking rs.wasNull() is incorrect compared to checking result == null.

Just wanted some input on the logic here.

I overrode the getResult() method to solve my problem, but it seems to me my use case could be a common situation?

- GMK.

Iwao AVE!

unread,
Jun 10, 2019, 1:59:30 PM6/10/19
to mybatis-user
Thanks for the feedback, Graeme !

I agree with you.
And we actually removed the wasNull check in 3.5.0. ;)

Check the release notes and see if it's possible to upgrade to the latest version 3.5.1.

Regards,
Iwao


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/2f533ce7-1fea-4407-99b9-ffa0c39aede2%40googlegroups.com.

Graeme Knight

unread,
Jun 10, 2019, 2:08:41 PM6/10/19
to mybatis-user
Dear Iwao,

Many thanks for your reply. That's wonderful news! We just implemented MyBatis but I will notify the team to upgrade (and keep up to date) with the newer versions! 

Sorry to have been 'past history' here.

GMK.
To unsubscribe from this group and stop receiving emails from it, send an email to mybati...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages