You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Jakub Scheibe <ja...@gmail.com> on 2007/03/15 12:40:43 UTC

Select problem...

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?

Re: Select problem...

Posted by Jakub Scheibe <ja...@gmail.com>.
Hi again.

May be i really didn't specified the problem properly.
I'll try to do it again.

I have 3 classes (class1, class2, class3).
Class2 is used inside class1 and class3 is used inside class2.
I want to call select for class1 and get all the data from the classes 2 and
3
in the result map of class1. The result map of class1 have matching prop
<result property="Class2.Test" column="Test" select="Class3"/>.
I can't create result map for Class2 cause there is no db table
related with this class. So in that situation I'm getting message:
unable cast class1 to class2.

Regards,
Jakub.

Re: Select problem...

Posted by Jakub Scheibe <ja...@gmail.com>.
As I wrote, I have 3 classes. Each of them have a lot props.
I want to get all the values from the class3 calling select all
from class1.

On 15/03/07, Bob Hanson <mn...@gmail.com> wrote:
>
> 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 <ja...@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 <ja...@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?
> > > >
> > >
> >
> >
>

Re: Select problem...

Posted by Bob Hanson <mn...@gmail.com>.
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 <ja...@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 <ja...@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?
> > >
> >
>
>

Re: Select problem...

Posted by Jakub Scheibe <ja...@gmail.com>.
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 <mn...@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 <ja...@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?
> >
>

Re: Select problem...

Posted by Bob Hanson <mn...@gmail.com>.
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 <ja...@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?
>

ORA-01461: can bind a LONG value only for insert into a LONG column

Posted by Henry Lu <zh...@umich.edu>.
I got the error:

ORA-01461: can bind a LONG value only for insert into a LONG column

When I do insert. But there is nothing to do with any LONG column in the 
table. And All values of columns inserted were less than the size in the 
table.

Is there any idea how to fix?

-Henry