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 21:14:19 GMT
A WAG here - what driver are you using?

Larry


On Thu, May 1, 2008 at 3:07 PM, David Momper <david.momper@fedex.com> wrote:
> Just for an update in my efforts to track down this error, I put in
>  breakpoints, and the setters for the fields that are coming up null are
>  never called.  For the fields where the setters are called, everything is
>  set and displays properly.
>
>  On advice from Larry, I made some changes to my xml file.  While these
>  changes have not fixed the problem, they make the file much smaller, so it
>  should be easier to spot an error there if there is one (I can't find any).
>
>  I also changed the date fields in my airport class to be of type
>  java.util.Date, instead of String.  I still get no return value from these
>  fields.
>
>  The new xml file (no longer has a resultmap):
>  <sqlMap namespace="Airport">
>
> <select id="getAirportList" resultClass="domain.Airport">
>  SELECT
>
>         AIRPORT.AIRPORT_ID as "id",
>         AIRPORT.IATA_CODE as "iataCode",
>         AIRPORT.ICAO_CODE as "icaoCode",
>         AIRPORT.LATITUDE as "latitude",
>         AIRPORT.LONGITUDE as "longitude",
>         AIRPORT.START_DATE as "startDate",
>         AIRPORT.END_DATE as "endDate",
>         AIRPORT_NAME.NAME as "name"
>
> FROM AIRPORT, AIRPORT_NAME
>  WHERE
>         AIRPORT.AIRPORT_ID = AIRPORT_NAME.AIRPORT_ID AND
>         AIRPORT_NAME.MAIN_FLG = 1
>  </select>
>  </sqlMap>
>
>
> -----Original Message-----
>  From: David Momper [mailto:david.momper@fedex.com]
>  Sent: Thursday, May 01, 2008 11:56 AM
>  To: user-java@ibatis.apache.org
>
>
> Subject: DAO class not getting values from query
>
>  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