You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by macdoug1 <ma...@swbell.net> on 2007/03/28 20:15:39 UTC

How does this work? sqlMap

I can't seem to figure out from reading the documentation how this actually
works but I'm hoping that someone can either give me some help with this
issue or point me in the direction of an example that is similiar enough to
figure it out. Anyway here is what I picked up in the sqlMap stuff:
[CODE]<resultMap id="result"
class="org.springframework.samples.jpetstore.domain.Item">
    <result property="itemId" column="itemid" columnIndex="1"/>
    <result property="listPrice" column="listprice" columnIndex="2"/>
    <result property="unitCost" column="unitcost" columnIndex="3"/>
    <result property="supplierId" column="supplier" columnIndex="4"/>
    <result property="productId" column="productid" columnIndex="5"/>
    <result property="product.productId" column="productid"
columnIndex="5"/>
    <result property="product.name" column="name" columnIndex="6"/>
    <result property="product.description" column="descn" columnIndex="7"/>
    <result property="product.categoryId" column="category"
columnIndex="8"/>
    <result property="status" column="status" columnIndex="9"/>
    <result property="attribute1" column="attr1" columnIndex="10"/>
    <result property="attribute2" column="attr2" columnIndex="11"/>
    <result property="attribute3" column="attr3" columnIndex="12"/>
    <result property="attribute4" column="attr4" columnIndex="13"/>
    <result property="attribute5" column="attr5" columnIndex="14"/>
  </resultMap>

  <resultMap id="result-with-quantity"
class="org.springframework.samples.jpetstore.domain.Item">
    <result property="itemId" column="itemid" columnIndex="1"/>
    <result property="listPrice" column="listprice" columnIndex="2"/>
    <result property="unitCost" column="unitcost" columnIndex="3"/>
    <result property="supplierId" column="supplier" columnIndex="4"/>
    <result property="productId" column="productid" columnIndex="5"/>
    <result property="product.productId" column="productid"
columnIndex="5"/>
    <result property="product.name" column="name" columnIndex="6"/>
    <result property="product.description" column="descn" columnIndex="7"/>
    <result property="product.categoryId" column="category"
columnIndex="8"/>
    <result property="status" column="status" columnIndex="9"/>
    <result property="attribute1" column="attr1" columnIndex="10"/>
    <result property="attribute2" column="attr2" columnIndex="11"/>
    <result property="attribute3" column="attr3" columnIndex="12"/>
    <result property="attribute4" column="attr4" columnIndex="13"/>
    <result property="attribute5" column="attr5" columnIndex="14"/>
    <result property="quantity" column="qty" columnIndex="15"/>
  </resultMap>
[/CODE]
So my issue is that here you use the same class for the resultMap except the
query itself defines two separate resultMaps: one which is just result and
the other which is result-with-quantity. My question is how does this work?
My issue is that I've created a my bean and it has all the getter/setters in
it for all the columns that I want to retrieve and in one case I use some of
them (much like the first example here "result") and then in another case I
use some different ones (sort of similiar to the second one
"result-with-quantity") Here's my example:[CODE]public class Item implements
Serializable {

  /* Private Fields */

  private String itemId;
  private String productId;
  private double listPrice;
  private double unitCost;
  private int supplierId;
  private String status;
  private String attribute1;
  private String attribute2;
  private String attribute3;
  private String attribute4;
  private String attribute5;
  private Product product;
  private int quantity;

  /* JavaBeans Properties */

  public String getItemId() { return itemId; }
  public void setItemId(String itemId) { this.itemId = itemId.trim(); }

  public int getQuantity() { return quantity; }
  public void setQuantity(int quantity) { this.quantity = quantity; }

  public Product getProduct() { return product; }
  public void setProduct(Product product) { this.product = product; }

  public String getProductId() { return productId; }
  public void setProductId(String productId) { this.productId = productId; }

  public int getSupplierId() { return supplierId; }
  public void setSupplierId(int supplierId) { this.supplierId = supplierId;
}

  public double getListPrice() { return listPrice; }
  public void setListPrice(double listPrice) { this.listPrice = listPrice; }

  public double getUnitCost() { return unitCost; }
  public void setUnitCost(double unitCost) { this.unitCost = unitCost; }

  public String getStatus() { return status; }
  public void setStatus(String status) { this.status = status; }

  public String getAttribute1() { return attribute1; }
  public void setAttribute1(String attribute1) { this.attribute1 =
attribute1; }

  public String getAttribute2() { return attribute2; }
  public void setAttribute2(String attribute2) { this.attribute2 =
attribute2; }

  public String getAttribute3() { return attribute3; }
  public void setAttribute3(String attribute3) { this.attribute3 =
attribute3; }

  public String getAttribute4() { return attribute4; }
  public void setAttribute4(String attribute4) { this.attribute4 =
attribute4; }

  public String getAttribute5() { return attribute5; }
  public void setAttribute5(String attribute5) { this.attribute5 =
attribute5; }
[/CODE] and [CODE]<resultMap id="result"
class="org.springframework.samples.jpetstore.domain.Item">
    <result property="itemId" column="itemid" columnIndex="1"/>
    <result property="listPrice" column="listprice" columnIndex="2"/>
    <result property="unitCost" column="unitcost" columnIndex="3"/>
    <result property="supplierId" column="supplier" columnIndex="4"/>
    <result property="productId" column="productid" columnIndex="5"/>
    <result property="product.productId" column="productid"
columnIndex="5"/>
    <result property="product.name" column="name" columnIndex="6"/>
    <result property="product.description" column="descn" columnIndex="7"/>
    <result property="product.categoryId" column="category"
columnIndex="8"/>
    <result property="status" column="status" columnIndex="9"/>
    <result property="attribute1" column="attr1" columnIndex="10"/>
    <result property="attribute2" column="attr2" columnIndex="11"/>
    <result property="attribute3" column="attr3" columnIndex="12"/>
    <result property="attribute4" column="attr4" columnIndex="13"/>
    <result property="attribute5" column="attr5" columnIndex="14"/>
  </resultMap>
[/CODE] and the one that I want for a second resultMap [CODE]<resultMap
id="result-with-quantity"
class="org.springframework.samples.jpetstore.domain.Item">
    <result property="itemId" column="itemid" columnIndex="1"/>
    <result property="listPrice" column="listprice" columnIndex="2"/>
    <result property="unitCost" column="unitcost" columnIndex="3"/>
    <result property="supplierId" column="supplier" columnIndex="4"/>
<result property="attribute1" column="attr1" columnIndex="5"/>
    <result property="attribute2" column="attr2" columnIndex="6"/>
    <result property="attribute3" column="attr3" columnIndex="7"/>
<result property="quantity" column="qty" columnIndex="8"/>
  </resultMap>
[/CODE] 
Anyway if I can understand how this works I might be able to get this to
work. Can anyone help here?

-- 
View this message in context: http://www.nabble.com/How-does-this-work--sqlMap-tf3481743.html#a9718396
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: How does this work? sqlMap

Posted by Ted Schrader <te...@gmail.com>.
I haven't looked at JPetStore, but my guess is that the "result"
result map is used with some of the <select>s, and the
"result-with-quantity" result map is used with others.  So, the actual
resultMap being used is driven by which statement id is being passed
into queryForObject() or queryForList().

Check the "resultMap" attribute on the <select> mappings within the
same SQLMap file to see which is used where.

Ted

On 28/03/07, macdoug1 <ma...@swbell.net> wrote:
>
> I can't seem to figure out from reading the documentation how this actually
> works but I'm hoping that someone can either give me some help with this
> issue or point me in the direction of an example that is similiar enough to
> figure it out. Anyway here is what I picked up in the sqlMap stuff:
> [CODE]<resultMap id="result"
> class="org.springframework.samples.jpetstore.domain.Item">
>     <result property="itemId" column="itemid" columnIndex="1"/>
>     <result property="listPrice" column="listprice" columnIndex="2"/>
>     <result property="unitCost" column="unitcost" columnIndex="3"/>
>     <result property="supplierId" column="supplier" columnIndex="4"/>
>     <result property="productId" column="productid" columnIndex="5"/>
>     <result property="product.productId" column="productid"
> columnIndex="5"/>
>     <result property="product.name" column="name" columnIndex="6"/>
>     <result property="product.description" column="descn" columnIndex="7"/>
>     <result property="product.categoryId" column="category"
> columnIndex="8"/>
>     <result property="status" column="status" columnIndex="9"/>
>     <result property="attribute1" column="attr1" columnIndex="10"/>
>     <result property="attribute2" column="attr2" columnIndex="11"/>
>     <result property="attribute3" column="attr3" columnIndex="12"/>
>     <result property="attribute4" column="attr4" columnIndex="13"/>
>     <result property="attribute5" column="attr5" columnIndex="14"/>
>   </resultMap>
>
>   <resultMap id="result-with-quantity"
> class="org.springframework.samples.jpetstore.domain.Item">
>     <result property="itemId" column="itemid" columnIndex="1"/>
>     <result property="listPrice" column="listprice" columnIndex="2"/>
>     <result property="unitCost" column="unitcost" columnIndex="3"/>
>     <result property="supplierId" column="supplier" columnIndex="4"/>
>     <result property="productId" column="productid" columnIndex="5"/>
>     <result property="product.productId" column="productid"
> columnIndex="5"/>
>     <result property="product.name" column="name" columnIndex="6"/>
>     <result property="product.description" column="descn" columnIndex="7"/>
>     <result property="product.categoryId" column="category"
> columnIndex="8"/>
>     <result property="status" column="status" columnIndex="9"/>
>     <result property="attribute1" column="attr1" columnIndex="10"/>
>     <result property="attribute2" column="attr2" columnIndex="11"/>
>     <result property="attribute3" column="attr3" columnIndex="12"/>
>     <result property="attribute4" column="attr4" columnIndex="13"/>
>     <result property="attribute5" column="attr5" columnIndex="14"/>
>     <result property="quantity" column="qty" columnIndex="15"/>
>   </resultMap>
> [/CODE]
> So my issue is that here you use the same class for the resultMap except the
> query itself defines two separate resultMaps: one which is just result and
> the other which is result-with-quantity. My question is how does this work?
> My issue is that I've created a my bean and it has all the getter/setters in
> it for all the columns that I want to retrieve and in one case I use some of
> them (much like the first example here "result") and then in another case I
> use some different ones (sort of similiar to the second one
> "result-with-quantity") Here's my example:[CODE]public class Item implements
> Serializable {
>
>   /* Private Fields */
>
>   private String itemId;
>   private String productId;
>   private double listPrice;
>   private double unitCost;
>   private int supplierId;
>   private String status;
>   private String attribute1;
>   private String attribute2;
>   private String attribute3;
>   private String attribute4;
>   private String attribute5;
>   private Product product;
>   private int quantity;
>
>   /* JavaBeans Properties */
>
>   public String getItemId() { return itemId; }
>   public void setItemId(String itemId) { this.itemId = itemId.trim(); }
>
>   public int getQuantity() { return quantity; }
>   public void setQuantity(int quantity) { this.quantity = quantity; }
>
>   public Product getProduct() { return product; }
>   public void setProduct(Product product) { this.product = product; }
>
>   public String getProductId() { return productId; }
>   public void setProductId(String productId) { this.productId = productId; }
>
>   public int getSupplierId() { return supplierId; }
>   public void setSupplierId(int supplierId) { this.supplierId = supplierId;
> }
>
>   public double getListPrice() { return listPrice; }
>   public void setListPrice(double listPrice) { this.listPrice = listPrice; }
>
>   public double getUnitCost() { return unitCost; }
>   public void setUnitCost(double unitCost) { this.unitCost = unitCost; }
>
>   public String getStatus() { return status; }
>   public void setStatus(String status) { this.status = status; }
>
>   public String getAttribute1() { return attribute1; }
>   public void setAttribute1(String attribute1) { this.attribute1 =
> attribute1; }
>
>   public String getAttribute2() { return attribute2; }
>   public void setAttribute2(String attribute2) { this.attribute2 =
> attribute2; }
>
>   public String getAttribute3() { return attribute3; }
>   public void setAttribute3(String attribute3) { this.attribute3 =
> attribute3; }
>
>   public String getAttribute4() { return attribute4; }
>   public void setAttribute4(String attribute4) { this.attribute4 =
> attribute4; }
>
>   public String getAttribute5() { return attribute5; }
>   public void setAttribute5(String attribute5) { this.attribute5 =
> attribute5; }
> [/CODE] and [CODE]<resultMap id="result"
> class="org.springframework.samples.jpetstore.domain.Item">
>     <result property="itemId" column="itemid" columnIndex="1"/>
>     <result property="listPrice" column="listprice" columnIndex="2"/>
>     <result property="unitCost" column="unitcost" columnIndex="3"/>
>     <result property="supplierId" column="supplier" columnIndex="4"/>
>     <result property="productId" column="productid" columnIndex="5"/>
>     <result property="product.productId" column="productid"
> columnIndex="5"/>
>     <result property="product.name" column="name" columnIndex="6"/>
>     <result property="product.description" column="descn" columnIndex="7"/>
>     <result property="product.categoryId" column="category"
> columnIndex="8"/>
>     <result property="status" column="status" columnIndex="9"/>
>     <result property="attribute1" column="attr1" columnIndex="10"/>
>     <result property="attribute2" column="attr2" columnIndex="11"/>
>     <result property="attribute3" column="attr3" columnIndex="12"/>
>     <result property="attribute4" column="attr4" columnIndex="13"/>
>     <result property="attribute5" column="attr5" columnIndex="14"/>
>   </resultMap>
> [/CODE] and the one that I want for a second resultMap [CODE]<resultMap
> id="result-with-quantity"
> class="org.springframework.samples.jpetstore.domain.Item">
>     <result property="itemId" column="itemid" columnIndex="1"/>
>     <result property="listPrice" column="listprice" columnIndex="2"/>
>     <result property="unitCost" column="unitcost" columnIndex="3"/>
>     <result property="supplierId" column="supplier" columnIndex="4"/>
> <result property="attribute1" column="attr1" columnIndex="5"/>
>     <result property="attribute2" column="attr2" columnIndex="6"/>
>     <result property="attribute3" column="attr3" columnIndex="7"/>
> <result property="quantity" column="qty" columnIndex="8"/>
>   </resultMap>
> [/CODE]
> Anyway if I can understand how this works I might be able to get this to
> work. Can anyone help here?
>
> --
> View this message in context: http://www.nabble.com/How-does-this-work--sqlMap-tf3481743.html#a9718396
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>