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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Graeme Knight
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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/2f533ce7-1fea-4407-99b9-ffa0c39aede2%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

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

Iwao AVE!
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


On Tue, Jun 11, 2019 at 1:11 AM Graeme Knight <[hidden email]> wrote:
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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/2f533ce7-1fea-4407-99b9-ffa0c39aede2%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/CA%2Buep2Te0ArQ3YMji53qb65D0Hiz0kZeS9LCyo32_VRLYiC6gA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

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

Graeme Knight
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.

On Monday, June 10, 2019 at 1:59:30 PM UTC-4, Iwao AVE! wrote:
Thanks for the feedback, Graeme !

I agree with you.
And we actually removed the wasNull check in 3.5.0. ;)
<a href="https://github.com/mybatis/mybatis-3/pull/1244" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Fpull%2F1244\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHIxdGsdFk3I-fbO1jmggCM26G9bA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Fpull%2F1244\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHIxdGsdFk3I-fbO1jmggCM26G9bA&#39;;return true;">https://github.com/mybatis/mybatis-3/pull/1244

Check the release notes and see if it's possible to upgrade to the latest version 3.5.1.
<a href="https://github.com/mybatis/mybatis-3/releases" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Freleases\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF0CtQFk6qlB7JWEtIGKZDAkXZEog&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Freleases\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF0CtQFk6qlB7JWEtIGKZDAkXZEog&#39;;return true;">https://github.com/mybatis/mybatis-3/releases

Regards,
Iwao


On Tue, Jun 11, 2019 at 1:11 AM Graeme Knight <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="0M6IGIFyAQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">graem...@...> wrote:
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.

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="0M6IGIFyAQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybati...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/mybatis-user/2f533ce7-1fea-4407-99b9-ffa0c39aede2%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/mybatis-user/2f533ce7-1fea-4407-99b9-ffa0c39aede2%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/mybatis-user/2f533ce7-1fea-4407-99b9-ffa0c39aede2%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/mybatis-user/2f533ce7-1fea-4407-99b9-ffa0c39aede2%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/f1177e1a-5d91-48b9-b43a-f61e12dfbbdc%40googlegroups.com.