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 钟原froast <fr...@gmail.com> on 2007/08/01 03:34:23 UTC

[ibatis2]can I use a class with inner classes as resultMap?

hi, I have a class like this:

package com.gehouse.bean.ge;

public class GEElementStyleBean {


 public class IconStyle {
  int id;
  float scale;
  boolean transparent;
  public int getId() {
   return id;
  }
  public void setId(int id) {
   this.id = id;
  }
  public float getScale() {
   return scale;
  }
  public void setScale(float scale) {
   this.scale = scale;
  }
  public boolean isTransparent() {
   return transparent;
  }
  public void setTransparent(boolean transparent) {
   this.transparent = transparent;
  }
 }

 public class LableStyle {
  String color;
  float scale;
  public String getColor() {
   return color;
  }
  public void setColor(String color) {
   this.color = color;
  }
  public float getScale() {
   return scale;
  }
  public void setScale(float scale) {
   this.scale = scale;
  }
 }

 public class LineStyle {
  String color;
  float scale;
  public String getColor() {
   return color;
  }
  public void setColor(String color) {
   this.color = color;
  }
  public float getScale() {
   return scale;
  }
  public void setScale(float scale) {
   this.scale = scale;
  }
 }

 private IconStyle iconStyle;
 private LableStyle lableStyle;
 private LineStyle lineStyle;

 public IconStyle getIconStyle() {
  return iconStyle;
 }

 public void setIconStyle(IconStyle iconStyle) {
  this.iconStyle = iconStyle;
 }

 public LableStyle getLableStyle() {
  return lableStyle;
 }

 public void setLableStyle(LableStyle lableStyle) {
  this.lableStyle = lableStyle;
 }

 public LineStyle getLineStyle() {
  return lineStyle;
 }

 public void setLineStyle(LineStyle lineStyle) {
  this.lineStyle = lineStyle;
 }
}
-----------------------------------------------------------------------------------------------------------------

and result map like this:

<typeAlias alias="GEStyle" type="com.gehouse.bean.ge.GEElementStyleMapBean
"></typeAlias>
 <typeAlias alias="GEElementStyle" type="
com.gehouse.bean.ge.GEElementStyleBean"></typeAlias>

 <resultMap id="GEStyleResultMap" class="GEStyle">
   <result property="id" column="id"/>
   <result property="name" column="name"/>

   <result property="normalStyle.iconStyle.id" column="nomal_icon_id"/>
   <result property="normalStyle.iconStyle.scale"
column="normal_icon_scale"/>
   <result property="normalStyle.iconStyle.transparent"
column="normal_icon_transprent"/>
   <result property="normalStyle.lableStyle.color"
column="normal_label_color"/>
   <result property="normalStyle.lableStyle.scale"
column="normal_label_scale"/>
   <result property="normalStyle.lineStyle.color"
column="normal_line_color"/>
   <result property="normalStyle.lineStyle.scale"
column="normal_line_width"/>

   <result property="highlightStyle.iconStyle.id"
column="highlight_icon_id"/>
   <result property="highlightStyle.iconStyle.scale"
column="highlight_icon_scale"/>
   <result property="highlightStyle.iconStyle.transparent"
column="highlight_icon_transprent"/>
   <result property="highlightStyle.lableStyle.color"
column="highlight_label_color"/>
   <result property="highlightStyle.lableStyle.scale"
column="highlight_label_scale"/>
   <result property="highlightStyle.lineStyle.color"
column="highlight_line_color"/>
   <result property="highlightStyle.lineStyle.scale"
column="highlight_line_width"/>

  </resultMap>

--------------------------------------------------------------------------------------------------------------

but it throws exceptions, saying that normalStyle.iconStyle is null, all the
inner class objects are null, the ibatis can't initialize the object.

is there any solutions? any help would be appreciated.

Re: [ibatis2]can I use a class with inner classes as resultMap?

Posted by Jiming Liu <ji...@gmail.com>.
public class GEElementStyleBean {

...

public LableStyle getLableStyle() {
if(null==labelStyle) lableStyle=new LabelStyle();
return lableStyle;
}


...
}

On 8/1/07, Brandon Goodin <br...@gmail.com> wrote:
>
> I'm not seeing where you initialize your inner classes. All I see is the
> following...
>
>  private IconStyle iconStyle;
>  private LableStyle lableStyle;
>  private LineStyle lineStyle;
>
> They would be null at this point.
>
> Brandon
>
> On 7/31/07, 钟原froast <fr...@gmail.com> wrote:
> >
> > hi, I have a class like this:
> >
> > package com.gehouse.bean.ge;
> >
> > public class GEElementStyleBean {
> >
> >
> >  public class IconStyle {
> >   int id;
> >   float scale;
> >   boolean transparent;
> >   public int getId() {
> >    return id;
> >   }
> >   public void setId(int id) {
> >     this.id = id;
> >   }
> >   public float getScale() {
> >    return scale;
> >   }
> >   public void setScale(float scale) {
> >    this.scale = scale;
> >   }
> >   public boolean isTransparent() {
> >    return transparent;
> >   }
> >   public void setTransparent(boolean transparent) {
> >    this.transparent = transparent;
> >   }
> >  }
> >
> >  public class LableStyle {
> >   String color;
> >   float scale;
> >   public String getColor() {
> >    return color;
> >   }
> >   public void setColor(String color) {
> >    this.color = color;
> >   }
> >   public float getScale() {
> >    return scale;
> >   }
> >   public void setScale(float scale) {
> >    this.scale = scale;
> >   }
> >  }
> >
> >  public class LineStyle {
> >   String color;
> >   float scale;
> >   public String getColor() {
> >    return color;
> >   }
> >   public void setColor(String color) {
> >    this.color = color;
> >   }
> >   public float getScale() {
> >    return scale;
> >   }
> >   public void setScale(float scale) {
> >    this.scale = scale;
> >   }
> >  }
> >
> >  private IconStyle iconStyle;
> >  private LableStyle lableStyle;
> >  private LineStyle lineStyle;
> >
> >  public IconStyle getIconStyle() {
> >   return iconStyle;
> >  }
> >
> >  public void setIconStyle(IconStyle iconStyle) {
> >   this.iconStyle = iconStyle;
> >  }
> >
> >  public LableStyle getLableStyle() {
> >   return lableStyle;
> >  }
> >
> >  public void setLableStyle(LableStyle lableStyle) {
> >   this.lableStyle = lableStyle;
> >  }
> >
> >  public LineStyle getLineStyle() {
> >   return lineStyle;
> >  }
> >
> >  public void setLineStyle(LineStyle lineStyle) {
> >   this.lineStyle = lineStyle;
> >  }
> > }
> > -----------------------------------------------------------------------------------------------------------------
> >
> >
> > and result map like this:
> >
> > <typeAlias alias="GEStyle" type="
> > com.gehouse.bean.ge.GEElementStyleMapBean"></typeAlias>
> >  <typeAlias alias="GEElementStyle" type="
> > com.gehouse.bean.ge.GEElementStyleBean "></typeAlias>
> >
> >  <resultMap id="GEStyleResultMap" class="GEStyle">
> >    <result property="id" column="id"/>
> >    <result property="name" column="name"/>
> >
> >    <result property="normalStyle.iconStyle.id" column="nomal_icon_id"/>
> >    <result property="normalStyle.iconStyle.scale"
> > column="normal_icon_scale"/>
> >    <result property="normalStyle.iconStyle.transparent"
> > column="normal_icon_transprent"/>
> >    <result property="normalStyle.lableStyle.color"
> > column="normal_label_color"/>
> >    <result property="normalStyle.lableStyle.scale"
> > column="normal_label_scale"/>
> >    <result property="normalStyle.lineStyle.color"
> > column="normal_line_color"/>
> >    <result property="normalStyle.lineStyle.scale"
> > column="normal_line_width"/>
> >
> >    <result property=" highlightStyle.iconStyle.id"
> > column="highlight_icon_id"/>
> >    <result property="highlightStyle.iconStyle.scale"
> > column="highlight_icon_scale"/>
> >    <result property="highlightStyle.iconStyle.transparent"
> > column="highlight_icon_transprent"/>
> >    <result property="highlightStyle.lableStyle.color"
> > column="highlight_label_color"/>
> >    <result property="highlightStyle.lableStyle.scale"
> > column="highlight_label_scale"/>
> >    <result property="highlightStyle.lineStyle.color"
> > column="highlight_line_color"/>
> >    <result property="highlightStyle.lineStyle.scale"
> > column="highlight_line_width"/>
> >
> >   </resultMap>
> >
> >
> > --------------------------------------------------------------------------------------------------------------
> >
> > but it throws exceptions, saying that normalStyle.iconStyle is null, all
> > the inner class objects are null, the ibatis can't initialize the object.
> >
> > is there any solutions? any help would be appreciated.
> >
>
>

Re: [ibatis2]can I use a class with inner classes as resultMap?

Posted by Brandon Goodin <br...@gmail.com>.
I'm not seeing where you initialize your inner classes. All I see is the
following...

 private IconStyle iconStyle;
 private LableStyle lableStyle;
 private LineStyle lineStyle;

They would be null at this point.

Brandon

On 7/31/07, 钟原froast <fr...@gmail.com> wrote:
>
> hi, I have a class like this:
>
> package com.gehouse.bean.ge;
>
> public class GEElementStyleBean {
>
>
>  public class IconStyle {
>   int id;
>   float scale;
>   boolean transparent;
>   public int getId() {
>    return id;
>   }
>   public void setId(int id) {
>    this.id = id;
>   }
>   public float getScale() {
>    return scale;
>   }
>   public void setScale(float scale) {
>    this.scale = scale;
>   }
>   public boolean isTransparent() {
>    return transparent;
>   }
>   public void setTransparent(boolean transparent) {
>    this.transparent = transparent;
>   }
>  }
>
>  public class LableStyle {
>   String color;
>   float scale;
>   public String getColor() {
>    return color;
>   }
>   public void setColor(String color) {
>    this.color = color;
>   }
>   public float getScale() {
>    return scale;
>   }
>   public void setScale(float scale) {
>    this.scale = scale;
>   }
>  }
>
>  public class LineStyle {
>   String color;
>   float scale;
>   public String getColor() {
>    return color;
>   }
>   public void setColor(String color) {
>    this.color = color;
>   }
>   public float getScale() {
>    return scale;
>   }
>   public void setScale(float scale) {
>    this.scale = scale;
>   }
>  }
>
>  private IconStyle iconStyle;
>  private LableStyle lableStyle;
>  private LineStyle lineStyle;
>
>  public IconStyle getIconStyle() {
>   return iconStyle;
>  }
>
>  public void setIconStyle(IconStyle iconStyle) {
>   this.iconStyle = iconStyle;
>  }
>
>  public LableStyle getLableStyle() {
>   return lableStyle;
>  }
>
>  public void setLableStyle(LableStyle lableStyle) {
>   this.lableStyle = lableStyle;
>  }
>
>  public LineStyle getLineStyle() {
>   return lineStyle;
>  }
>
>  public void setLineStyle(LineStyle lineStyle) {
>   this.lineStyle = lineStyle;
>  }
> }
> -----------------------------------------------------------------------------------------------------------------
>
>
> and result map like this:
>
> <typeAlias alias="GEStyle" type="com.gehouse.bean.ge.GEElementStyleMapBean
> "></typeAlias>
>  <typeAlias alias="GEElementStyle" type="
> com.gehouse.bean.ge.GEElementStyleBean "></typeAlias>
>
>  <resultMap id="GEStyleResultMap" class="GEStyle">
>    <result property="id" column="id"/>
>    <result property="name" column="name"/>
>
>    <result property="normalStyle.iconStyle.id" column="nomal_icon_id"/>
>    <result property="normalStyle.iconStyle.scale"
> column="normal_icon_scale"/>
>    <result property="normalStyle.iconStyle.transparent"
> column="normal_icon_transprent"/>
>    <result property="normalStyle.lableStyle.color"
> column="normal_label_color"/>
>    <result property="normalStyle.lableStyle.scale"
> column="normal_label_scale"/>
>    <result property="normalStyle.lineStyle.color"
> column="normal_line_color"/>
>    <result property="normalStyle.lineStyle.scale"
> column="normal_line_width"/>
>
>    <result property="highlightStyle.iconStyle.id"
> column="highlight_icon_id"/>
>    <result property="highlightStyle.iconStyle.scale"
> column="highlight_icon_scale"/>
>    <result property="highlightStyle.iconStyle.transparent"
> column="highlight_icon_transprent"/>
>    <result property="highlightStyle.lableStyle.color"
> column="highlight_label_color"/>
>    <result property="highlightStyle.lableStyle.scale"
> column="highlight_label_scale"/>
>    <result property="highlightStyle.lineStyle.color"
> column="highlight_line_color"/>
>    <result property="highlightStyle.lineStyle.scale"
> column="highlight_line_width"/>
>
>   </resultMap>
>
>
> --------------------------------------------------------------------------------------------------------------
>
> but it throws exceptions, saying that normalStyle.iconStyle is null, all
> the inner class objects are null, the ibatis can't initialize the object.
>
> is there any solutions? any help would be appreciated.
>