Uploaded image for project: 'iBatis for Java [READ ONLY]'
  1. iBatis for Java [READ ONLY]
  2. IBATIS-776

Error if no resultType or resultMap provided in XML file, should iBatis be able to infer resultType from mapper interface?

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.0 Beta 10
    • 3.0 GA Candidate
    • Core
    • None
    • Using iBatis 3.0.0 GA candidate from Clinton 4/9/2010. MySQL 5.1. Windows 7/64. Running under Tomcat 6. Latest Java 6 JM.

    Description

      Situation:

      • using a Mapper interface together with a companion XML mapper file
      • testing a select query where the query is provided via <select> in the XML
      • the return type has been provided in the mapper interface, such as: MyObject selectMyObject(arg1, arg2)
      • MyObject is a Bean style class
      • the corresponding <select> with id "selectMyObject" does not specify a resultType or resultMap.

      What happens:

      • IndexOutOfBounds is thrown in FastResultSetHandler.handleMultipleResults()
      • This is because the resultMaps list is empty (size is zero), so the first call to resultMaps.get(count) fails

      I guess I assumed that in this case, iBatis would know the return type is MyObject and so I would be able to omit the resultType in the <select> block. Seems like that would be sweet behavior if possible, and more consistent with the nice way in which parameters are sniffed from the mapper interface. That would be expected behavior from my POV, not sure if others would agree or not.

      Either way I would propose putting a check in handleResultSets something like this (pseudocode), to make it easier for the developer to understand where the error is coming from (hard to figure out without stepping through the source, which is what I did):

      if (resultMaps.size() == 0) {
      throw new IllegalStateException("No result maps available, perhaps no a result type has been specified in the mapper?");
      }

      Attachments

        Activity

          People

            cbegin Clinton Begin
            thanny Nate Weiss
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: