ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bob Hanson" <mnbo...@gmail.com>
Subject Re: Select problem...
Date Thu, 15 Mar 2007 14:26:38 GMT
No you don't have to use properties. But the "Property" attribute in
the result map has to match a property or field in your class. So when
you used Test, I didn't know what you were trying to map to.

I'm still not positive what you are trying to do. A result map maps a
column from a database table to a property/field in a class. As I said
in my first reply, your original example showed you trying to map a
Class3 type into a property declared as type Class2. The error message
you were receiving indicates exactly that.

Your rmSelectClass1 result map needs to be:
    <resultMap id="rmSelectClass1" class="Class1">
      <result property="Id" column="ID"/>
      <result property="Test" column="Test" select="SelectClass2"/>
    </resultMap>

And then you need to define a result map for Class2.


On 3/15/07, Jakub Scheibe <jakub.scheibe@gmail.com> wrote:
> Ok here are my simplified classes
>
>     public class Class1
>     {
>
>         couple of props and methods
>
>         public Class2 Class2
>         {
>             get
>             {
>                 return _Class2;
>             }
>             set
>             {
>                 _Class2 = value;
>             }
>         }
>
>     public class Class2
>     {
>         private Class3 Class3;
>
>         public Class3
>         {
>             get
>             {
>                 return _Class3
>             }
>             set
>             {
>                 _Class3 = value;
>             }
>         }
>
> and Class3 with some props and methods.
>
> Do I really need to declare any prop ? Test was just an example of
> any property that i have in the classes.
>
>
> On 15/03/07, Bob Hanson < mnbob70@gmail.com> wrote:
> > Based on your example, class1 contains a public instance of class2, not
> class3.
> >
> > You also don't show any property named Test on your classes. If class1
> > has a property named Test which is declared as "public class2 Test",
> > then your result map for class1 needs to select a class2 object
> > instead of a class3 object.
> >
> > On 3/15/07, Jakub Scheibe <jakub.scheibe@gmail.com> wrote:
> > > Hi,
> > >
> > > I have 3 classes:
> > >
> > > class1
> > > {
> > >    public string id;
> > >    public class2 _class2;
> > > }
> > >
> > > class2
> > > {
> > >   public class3 _class3;
> > > }
> > >
> > > class3
> > > {
> > >   public string test;
> > > }
> > >
> > > The problem is when I'm trying to execute select command.
> > > I have 2 sqlmap.xml file for class1 and class3.
> > > f.e.
> > >
> > > class1.xml
> > >
> > >     <resultMap id="rmSelectClass1" class="Class1">
> > >       <result property="Id" column="ID"/>
> > >       <result property="Test" column="Test" select="SelectClass3"/>
> > >     </resultMap>
> > >
> > >     <select id="Class1Select" resultMap="rmSelectClass1">
> > >       select *
> > >       from my_table
> > >     </select>
> > >
> > > class3.xml
> > >
> > >     <resultMap id="rmSelectClass3" class="Class3">
> > >       <result property="Test" column="Test"/>
> > >     </resultMap>
> > >
> > >     <select id="SelectClass3" resultMap="rmClass3"">
> > >         select Test
> > >         from my_table2
> > >     </select>
> > >
> > > When i'm runing my test i'm getting following error:
> > > Unable to cast object of type 'Class3' to type 'Class2'
> > >
> > > Any help?
> > >
> >
>
>

Mime
View raw message