ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Larry Meadors" <larry.mead...@gmail.com>
Subject Re: DAO class not getting values from query
Date Thu, 01 May 2008 17:34:07 GMT
You have a result map, but specify a result class in the mapped statement.

I've never done anything so silly. ;-)

Larry


On Thu, May 1, 2008 at 10:55 AM, David Momper <david.momper@fedex.com> wrote:
> Hi all,
>  I have a page that displays a list or airports from a database query.  The
>  page displays the correct database values from some fields, null values from
>  others. Through debugging, I have figured out that the fields that display
>  as null are never set to begin with, but as best I can tell, they should be.
>
>  Some of the fields with problems are identical in structure to fields with
>  no problems. Latitude/longitude, and airport id are all Integers in my java
>  class, and are NUMBER in Oracle.  Lat/lon get proper values, id remains
>  null.  Of the fields I query, only latitude, longitude, and name get
>  non-null values.  I have verified that if I directly perform the query
>  against the database, all proper values are returned, so the query is not my
>  problem.  I suspect that the problem lies in my resultMap, but I haven't
>  been able to figure out what is wrong there.
>
>  I use Ibatis and Spring, with an Oracle 10g database. Relevant code is
>  included below.  Any help would be greatly appreciated.
>
>  The SQL map xml file:
>  <sqlMap namespace="Airport">
>         <resultMap id="result" class="domain.Airport">
>                 <result property="id" javaType="Integer" jdbcType="NUMBER"
>  column="AIRPORT_ID" columnIndex="1"/>
>                 <result property="iataCode" javaType="String"
>  jdbcType="CHAR(3)" column="IATA_CODE" columnIndex="2"/>
>                 <result property="icaoCode" javaType="String"
>  jdbcType="CHAR(4)" column="ICAO_CODE" columnIndex="3"/>
>                 <result property="latitude" javaType="Integer"
>  jdbcType="NUMBER" column="LATITUDE" columnIndex="4"/>
>                 <result property="longitude" javaType="Integer"
>  jdbcType="NUMBER" column="LONGITUDE" columnIndex="5"/>
>                 <result property="startDate" javaType="String"
>  jdbcType="TIMESTAMP" column="START_DATE" columnIndex="6"/>
>                 <result property="endDate" javaType="String"
>  jdbcType="TIMESTAMP" column="END_DATE" columnIndex="7"/>
>                 <result property="name" javaType="String"
>  jdbcType="VARCHAR2" column="NAME" columnIndex="8"/>
>         </resultMap>
>         <select id="getAirportList" resultClass="domain.Airport">
>         SELECT
>                 AIRPORT.AIRPORT_ID,
>                 AIRPORT.IATA_CODE,
>                 AIRPORT.ICAO_CODE,
>                 AIRPORT.LATITUDE,
>                 AIRPORT.LONGITUDE,
>                 AIRPORT.START_DATE,
>                 AIRPORT.END_DATE,
>                 AIRPORT_NAME.NAME
>         FROM AIRPORT, AIRPORT_NAME
>         WHERE AIRPORT.AIRPORT_ID = AIRPORT_NAME.AIRPORT_ID
>                 AND AIRPORT_NAME.MAIN_FLG = 1
>         </select>
>  </sqlMap>
>
>  AirportSqlMapDao class has:
>  public List<Airport> getAirportList() {
>         return
>  (List<Airport>)getSqlMapClientTemplate().queryForList("getAirportList");
>  }
>
>  The fields from the Airport class.  Getter/setter methods are typical
>  getter/setters.
>  private Integer id;
>         private String name;
>         private String iataCode;
>         private String icaoCode;
>         private Integer latitude;
>         private Integer longitude;
>         private String startDate, endDate;
>
>
>  My manager class:
>  public class SimpleAirportManager implements AirportManager {
>  private AirportDao airportDao;
>     public List<Airport> getAirports() {
>         return airportDao.getAirportList();
>     }
>     public void setAirportDao(AirportDao airportDao) {
>         this.airportDao = airportDao;
>     }
>  }
>
>  My controller has the code:
>  public ModelAndView handleRequest(HttpServletRequest request,
>  HttpServletResponse response) throws ServletException, IOException {
>         Map<String, Object> myModel = new HashMap<String, Object>();
>         myModel.put("airports", this.airportManager.getAirports());
>         return new ModelAndView("hello", "model", myModel);
>  }
>
>  This is the code from the display page:
>  <table border=1>
>  <tr><td>ID</td><td>Name</td><td>IATA code</td><td>ICAO
>  code</td><td>Latitude</td><td>Longitude</td><td>Start
Date</td><td>End
>  Date</td></tr>
>  <c:forEach items="${model.airports}" var="arpt">
>  <tr>
>  <td><c:out value="${arpt.id}"/></td>
>  <td><c:out value="${arpt.name}"/></td>
>  <td><c:out value="${arpt.iataCode}"/></td>
>  <td><c:out value="${arpt.icaoCode}"/></td>
>  <td><c:out value="${arpt.latitude}"/></td>
>  <td><c:out value="${arpt.longitude}"/></td>
>  <td><c:out value="${arpt.startDate}"/></td>
>  <td><c:out value="${arpt.endDate}"/></td>
>  </tr>
>  </c:forEach>
>  </table>
>
>

Mime
View raw message