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 Caio Zanchetti <ca...@gmail.com> on 2006/10/27 13:21:22 UTC

iBATIS Mapping

Guys, i'm using the ibatis in a project in my company, could you please help me?

The problem consists just in a retrive an object (of type Usuario)
from the database, this object contains an object of type Area. All
the others fields are OK (are populated perfectly). Only this object
(Area) is not instanced (and populated) by ibatis.

This situation happends very similar in the Demo ibatis jPetStore app,
with the classes Item and Procut. (Product is a field of Item). I
tryed to follow the same way they used to solve their problems in
their app.

The mapping and the tables of my app:

PS: The names are in brazilian portuguese:
Usuario - User
senha - password
grupo - group
nome - name
depto - dept
cargo - function
inativo - inactive

descricao - description (of an area).


* My tables:

USUARIO:
  "ID"	 INTEGER NOT NULL,
  "LOGIN"	 VARCHAR(15) NOT NULL,
  "SENHA"	 CHAR(80),
  "GRUPO"	 SMALLINT NOT NULL,
  "NOME"	 VARCHAR(60),
  "DEPTO"	 VARCHAR(20),
  "CARGO"	 VARCHAR(20),
  "INATIVO"	 VARCHAR(1),
  "EMAIL"	 VARCHAR(60),
  "AREA"	 INTEGER,


AREA
  "ID"	 INTEGER,
  "DESCRICAO"	 VARCHAR(30)
   ...


* My mapping file (the part where i'm working):
...
	select id="getById" parameterClass="java.lang.Integer" resultClass="Usuario"
		SELECT usuarios.id, login, senha, grupo, inativo, nome, depto, cargo, email,
                area AS "area.id",
                descricao AS "area.descricao"

                FROM usuarios, areas
                WHERE usuarios.area = areas.id
                AND usuarios.id=#id#
...



* The call in the DAO class:

    public Usuario getById(Integer id) {
        return (Usuario)
super.getSqlMapClientTemplate().queryForObject("getById", id);
    }


I believe that the POJOS will not necessary because it have only the
same tables structure.

There are two other solutions that are: Use a map for the return or
execute 2 selects in my DAO, I don't want to use no one of them.


Gratefful,

-- 
Claudiomir G. Zanchetti (Caio)
Sun Certified Programmer for the Java 2 Plataform, Standard Edition 5.0

Re: iBATIS Mapping

Posted by Caio Zanchetti <ca...@gmail.com>.
Hi Clinton, that's true, should work. But doesn't.
I will explain what is the Area class (i don't know if it was what you
ask me before): The Area class represents an Dept or Proccess in a
Company, this class has several fields but i believe that is not too
important.
I followed step by step of jPetStore app because the problem with Item
and Product is really simillar..
Maybe the problem could be the sql statement that i created.


Regards,



On 10/27/06, Clinton Begin <cl...@gmail.com> wrote:
> That should work....
>
> What does the area class look like?
>
> Cheers,
> Clinton
>
>
> On 10/27/06, Caio Zanchetti < caio.zanchetti@gmail.com> wrote:
> > Guys, i'm using the ibatis in a project in my company, could you please
> help me?
> >
> > The problem consists just in a retrive an object (of type Usuario)
> > from the database, this object contains an object of type Area. All
> > the others fields are OK (are populated perfectly). Only this object
> > (Area) is not instanced (and populated) by ibatis.
> >
> > This situation happends very similar in the Demo ibatis jPetStore app,
> > with the classes Item and Procut. (Product is a field of Item). I
> > tryed to follow the same way they used to solve their problems in
> > their app.
> >
> > The mapping and the tables of my app:
> >
> > PS: The names are in brazilian portuguese:
> > Usuario - User
> > senha - password
> > grupo - group
> > nome - name
> > depto - dept
> > cargo - function
> > inativo - inactive
> >
> > descricao - description (of an area).
> >
> >
> > * My tables:
> >
> > USUARIO:
> >   "ID"   INTEGER NOT NULL,
> >   "LOGIN"        VARCHAR(15) NOT NULL,
> >   "SENHA"        CHAR(80),
> >   "GRUPO"        SMALLINT NOT NULL,
> >   "NOME"         VARCHAR(60),
> >   "DEPTO"        VARCHAR(20),
> >   "CARGO"        VARCHAR(20),
> >   "INATIVO"      VARCHAR(1),
> >   "EMAIL"        VARCHAR(60),
> >   "AREA"         INTEGER,
> >
> >
> > AREA
> >   "ID"   INTEGER,
> >   "DESCRICAO"    VARCHAR(30)
> >    ...
> >
> >
> > * My mapping file (the part where i'm working):
> > ...
> >         select id="getById" parameterClass=" java.lang.Integer"
> resultClass="Usuario"
> >                 SELECT usuarios.id, login, senha, grupo, inativo, nome,
> depto, cargo, email,
> >                 area AS " area.id",
> >                 descricao AS "area.descricao"
> >
> >                 FROM usuarios, areas
> >                 WHERE usuarios.area = areas.id
> >                 AND usuarios.id=#id#
> > ...
> >
> >
> >
> > * The call in the DAO class:
> >
> >     public Usuario getById(Integer id) {
> >         return (Usuario)
> > super.getSqlMapClientTemplate().queryForObject("getById", id);
> >     }
> >
> >
> > I believe that the POJOS will not necessary because it have only the
> > same tables structure.
> >
> > There are two other solutions that are: Use a map for the return or
> > execute 2 selects in my DAO, I don't want to use no one of them.
> >
> >
> > Gratefful,
> >
> > --
> > Claudiomir G. Zanchetti (Caio)
> > Sun Certified Programmer for the Java 2 Plataform, Standard Edition 5.0
> >
>
>


-- 
Claudiomir G. Zanchetti (Caio)
Sun Certified Programmer for the Java 2 Plataform, Standard Edition 5.0

Re: iBATIS Mapping

Posted by Clinton Begin <cl...@gmail.com>.
That should work....

What does the area class look like?

Cheers,
Clinton

On 10/27/06, Caio Zanchetti <ca...@gmail.com> wrote:
>
> Guys, i'm using the ibatis in a project in my company, could you please
> help me?
>
> The problem consists just in a retrive an object (of type Usuario)
> from the database, this object contains an object of type Area. All
> the others fields are OK (are populated perfectly). Only this object
> (Area) is not instanced (and populated) by ibatis.
>
> This situation happends very similar in the Demo ibatis jPetStore app,
> with the classes Item and Procut. (Product is a field of Item). I
> tryed to follow the same way they used to solve their problems in
> their app.
>
> The mapping and the tables of my app:
>
> PS: The names are in brazilian portuguese:
> Usuario - User
> senha - password
> grupo - group
> nome - name
> depto - dept
> cargo - function
> inativo - inactive
>
> descricao - description (of an area).
>
>
> * My tables:
>
> USUARIO:
>   "ID"   INTEGER NOT NULL,
>   "LOGIN"        VARCHAR(15) NOT NULL,
>   "SENHA"        CHAR(80),
>   "GRUPO"        SMALLINT NOT NULL,
>   "NOME"         VARCHAR(60),
>   "DEPTO"        VARCHAR(20),
>   "CARGO"        VARCHAR(20),
>   "INATIVO"      VARCHAR(1),
>   "EMAIL"        VARCHAR(60),
>   "AREA"         INTEGER,
>
>
> AREA
>   "ID"   INTEGER,
>   "DESCRICAO"    VARCHAR(30)
>    ...
>
>
> * My mapping file (the part where i'm working):
> ...
>         select id="getById" parameterClass="java.lang.Integer"
> resultClass="Usuario"
>                 SELECT usuarios.id, login, senha, grupo, inativo, nome,
> depto, cargo, email,
>                 area AS "area.id",
>                 descricao AS "area.descricao"
>
>                 FROM usuarios, areas
>                 WHERE usuarios.area = areas.id
>                 AND usuarios.id=#id#
> ...
>
>
>
> * The call in the DAO class:
>
>     public Usuario getById(Integer id) {
>         return (Usuario)
> super.getSqlMapClientTemplate().queryForObject("getById", id);
>     }
>
>
> I believe that the POJOS will not necessary because it have only the
> same tables structure.
>
> There are two other solutions that are: Use a map for the return or
> execute 2 selects in my DAO, I don't want to use no one of them.
>
>
> Gratefful,
>
> --
> Claudiomir G. Zanchetti (Caio)
> Sun Certified Programmer for the Java 2 Plataform, Standard Edition 5.0
>

Re: R: R: iBATIS Mapping

Posted by Caio Zanchetti <ca...@gmail.com>.
Rinaldo, you are correct i need to retrive the data from the database,
but i'd like to use insted of a resultMap, an object of type Usuario
as resultClass (exactly like done in the mapping of the class Item in
the jPetStore app).
understand? if you don't feel free to ask.

Regards,


On 10/27/06, Rinaldo <rb...@sardiniapoint.it> wrote:
> So maybe I don't understand what is your problem.
>
> I suppose you need to retrieve the data from the database with the query
> correct?
>
> So create a Resultmap with all the column and the property you need
>
> Create a class with all the property you need that's all
> Ex.
>   <resultMap id="ridotta" class="ClassName">
>     <result column="ID" property="id" jdbcType="INTEGER"/>
>     <result column="LOGIN" property="login" jdbcType="VARCHAR"/>
>     <result column="SENHA" property="senha" jdbcType="VARCHAR"/>
> ...
>     <result column="EMAIL" property="email" jdbcType="VARCHAR"/>
>     <result column=" area.id " property="areaId" jdbcType="INTEGER"/>
>     <result column=" area.descricao " property=" descricao "
> jdbcType="VARCHAR"/>
>   </resultMap>
>
>         select id="getById" parameterClass="java.lang.Integer"
> resultClass="Usuario"
>                 SELECT t1.id, t1.login, t1.senha, t1.grupo, t1.inativo,
> t1.nome, t1.depto, t1.cargo, t1.email,
>                 t2.id as area,
>                 t2.descricao AS descricao
>
>                 FROM usuarios t1, areas t2
>                 WHERE t1.area = t2.id
>                 AND t1.id=#id#
> ...
> I use this system and all work fine
>
> Rinaldo
>
> -----Messaggio originale-----
> Da: Caio Zanchetti [mailto:caio.zanchetti@gmail.com]
> Inviato: venerdì 27 ottobre 2006 15.20
> A: user-java@ibatis.apache.org
> Oggetto: Re: R: iBATIS Mapping
>
> Rinaldo, tanks for reply.
> I don't understand what exactly is incorrect, can you explain please?
> But, anyway, i don't want to have the fields of Area in my Usuario.
> Only the object Area. (In Hibernate its possible through the mapping
> of a Component).
> Any doubt please ask me.
> Tanks
>
>
> On 10/27/06, Rinaldo <rb...@sardiniapoint.it> wrote:
> > Hi,
> > Control your Usuario class, it's seems that it's not correct
> >
> > Example
> >
> > Integer  ID;
> > String  LOGIN;
> > String  SENHA;
> > ...
> > String EMAIL;
> > Integer areaId;
> > String  areaDesc;
> >
> >
> >
> > Regards Rinaldo
> >
> >
> >
> > -----Messaggio originale-----
> > Da: Caio Zanchetti [mailto:caio.zanchetti@gmail.com]
> > Inviato: venerdì 27 ottobre 2006 13.21
> > A: user-java@ibatis.apache.org
> > Oggetto: iBATIS Mapping
> >
> > Guys, i'm using the ibatis in a project in my company, could you please
> help
> > me?
> >
> > The problem consists just in a retrive an object (of type Usuario)
> > from the database, this object contains an object of type Area. All
> > the others fields are OK (are populated perfectly). Only this object
> > (Area) is not instanced (and populated) by ibatis.
> >
> > This situation happends very similar in the Demo ibatis jPetStore app,
> > with the classes Item and Procut. (Product is a field of Item). I
> > tryed to follow the same way they used to solve their problems in
> > their app.
> >
> > The mapping and the tables of my app:
> >
> > PS: The names are in brazilian portuguese:
> > Usuario - User
> > senha - password
> > grupo - group
> > nome - name
> > depto - dept
> > cargo - function
> > inativo - inactive
> >
> > descricao - description (of an area).
> >
> >
> > * My tables:
> >
> > USUARIO:
> >   "ID"   INTEGER NOT NULL,
> >   "LOGIN"        VARCHAR(15) NOT NULL,
> >   "SENHA"        CHAR(80),
> >   "GRUPO"        SMALLINT NOT NULL,
> >   "NOME"         VARCHAR(60),
> >   "DEPTO"        VARCHAR(20),
> >   "CARGO"        VARCHAR(20),
> >   "INATIVO"      VARCHAR(1),
> >   "EMAIL"        VARCHAR(60),
> >   "AREA"         INTEGER,
> >
> >
> > AREA
> >   "ID"   INTEGER,
> >   "DESCRICAO"    VARCHAR(30)
> >    ...
> >
> >
> > * My mapping file (the part where i'm working):
> > ...
> >         select id="getById" parameterClass="java.lang.Integer"
> > resultClass="Usuario"
> >                 SELECT usuarios.id, login, senha, grupo, inativo, nome,
> > depto, cargo, email,
> >                 area AS "area.id",
> >                 descricao AS "area.descricao"
> >
> >                 FROM usuarios, areas
> >                 WHERE usuarios.area = areas.id
> >                 AND usuarios.id=#id#
> > ...
> >
> >
> >
> > * The call in the DAO class:
> >
> >     public Usuario getById(Integer id) {
> >         return (Usuario)
> > super.getSqlMapClientTemplate().queryForObject("getById", id);
> >     }
> >
> >
> > I believe that the POJOS will not necessary because it have only the
> > same tables structure.
> >
> > There are two other solutions that are: Use a map for the return or
> > execute 2 selects in my DAO, I don't want to use no one of them.
> >
> >
> > Gratefful,
> >
> > --
> > Claudiomir G. Zanchetti (Caio)
> > Sun Certified Programmer for the Java 2 Plataform, Standard Edition 5.0
> >
> > --
> > No virus found in this incoming message.
> > Checked by AVG Free Edition.
> > Version: 7.1.408 / Virus Database: 268.13.14/502 - Release Date:
> 27/10/2006
> >
> >
> > --
> > No virus found in this outgoing message.
> > Checked by AVG Free Edition.
> > Version: 7.1.408 / Virus Database: 268.13.14/502 - Release Date:
> 27/10/2006
> >
> >
> >
> >
>
>
> --
> Claudiomir G. Zanchetti (Caio)
> Sun Certified Programmer for the Java 2 Plataform, Standard Edition 5.0
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.408 / Virus Database: 268.13.14/502 - Release Date: 27/10/2006
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.408 / Virus Database: 268.13.14/502 - Release Date: 27/10/2006
>
>
>
>


-- 
Claudiomir G. Zanchetti (Caio)
Sun Certified Programmer for the Java 2 Plataform, Standard Edition 5.0

Re: R: iBATIS Mapping

Posted by Leandro Saad <le...@gmail.com>.
Hi Caio.

Please check the iBatis manual (pdf) on how to load Complex Properties (i.e.
a property of a class defined by the user). page 26.

:: Leandro

On 10/27/06, Caio Zanchetti <ca...@gmail.com> wrote:
>
> Rinaldo, tanks for reply.
> I don't understand what exactly is incorrect, can you explain please?
> But, anyway, i don't want to have the fields of Area in my Usuario.
> Only the object Area. (In Hibernate its possible through the mapping
> of a Component).
> Any doubt please ask me.
> Tanks
>
>
> On 10/27/06, Rinaldo <rb...@sardiniapoint.it> wrote:
> > Hi,
> > Control your Usuario class, it's seems that it's not correct
> >
> > Example
> >
> > Integer  ID;
> > String  LOGIN;
> > String  SENHA;
> > ...
> > String EMAIL;
> > Integer areaId;
> > String  areaDesc;
> >
> >
> >
> > Regards Rinaldo
> >
> >
> >
> > -----Messaggio originale-----
> > Da: Caio Zanchetti [mailto:caio.zanchetti@gmail.com]
> > Inviato: venerdì 27 ottobre 2006 13.21
> > A: user-java@ibatis.apache.org
> > Oggetto: iBATIS Mapping
> >
> > Guys, i'm using the ibatis in a project in my company, could you please
> help
> > me?
> >
> > The problem consists just in a retrive an object (of type Usuario)
> > from the database, this object contains an object of type Area. All
> > the others fields are OK (are populated perfectly). Only this object
> > (Area) is not instanced (and populated) by ibatis.
> >
> > This situation happends very similar in the Demo ibatis jPetStore app,
> > with the classes Item and Procut. (Product is a field of Item). I
> > tryed to follow the same way they used to solve their problems in
> > their app.
> >
> > The mapping and the tables of my app:
> >
> > PS: The names are in brazilian portuguese:
> > Usuario - User
> > senha - password
> > grupo - group
> > nome - name
> > depto - dept
> > cargo - function
> > inativo - inactive
> >
> > descricao - description (of an area).
> >
> >
> > * My tables:
> >
> > USUARIO:
> >   "ID"   INTEGER NOT NULL,
> >   "LOGIN"        VARCHAR(15) NOT NULL,
> >   "SENHA"        CHAR(80),
> >   "GRUPO"        SMALLINT NOT NULL,
> >   "NOME"         VARCHAR(60),
> >   "DEPTO"        VARCHAR(20),
> >   "CARGO"        VARCHAR(20),
> >   "INATIVO"      VARCHAR(1),
> >   "EMAIL"        VARCHAR(60),
> >   "AREA"         INTEGER,
> >
> >
> > AREA
> >   "ID"   INTEGER,
> >   "DESCRICAO"    VARCHAR(30)
> >    ...
> >
> >
> > * My mapping file (the part where i'm working):
> > ...
> >         select id="getById" parameterClass="java.lang.Integer"
> > resultClass="Usuario"
> >                 SELECT usuarios.id, login, senha, grupo, inativo, nome,
> > depto, cargo, email,
> >                 area AS "area.id",
> >                 descricao AS "area.descricao"
> >
> >                 FROM usuarios, areas
> >                 WHERE usuarios.area = areas.id
> >                 AND usuarios.id=#id#
> > ...
> >
> >
> >
> > * The call in the DAO class:
> >
> >     public Usuario getById(Integer id) {
> >         return (Usuario)
> > super.getSqlMapClientTemplate().queryForObject("getById", id);
> >     }
> >
> >
> > I believe that the POJOS will not necessary because it have only the
> > same tables structure.
> >
> > There are two other solutions that are: Use a map for the return or
> > execute 2 selects in my DAO, I don't want to use no one of them.
> >
> >
> > Gratefful,
> >
> > --
> > Claudiomir G. Zanchetti (Caio)
> > Sun Certified Programmer for the Java 2 Plataform, Standard Edition 5.0
> >
> > --
> > No virus found in this incoming message.
> > Checked by AVG Free Edition.
> > Version: 7.1.408 / Virus Database: 268.13.14/502 - Release Date:
> 27/10/2006
> >
> >
> > --
> > No virus found in this outgoing message.
> > Checked by AVG Free Edition.
> > Version: 7.1.408 / Virus Database: 268.13.14/502 - Release Date:
> 27/10/2006
> >
> >
> >
> >
>
>
> --
> Claudiomir G. Zanchetti (Caio)
> Sun Certified Programmer for the Java 2 Plataform, Standard Edition 5.0
>

R: R: iBATIS Mapping

Posted by Rinaldo <rb...@sardiniapoint.it>.
So maybe I don't understand what is your problem.

I suppose you need to retrieve the data from the database with the query
correct?

So create a Resultmap with all the column and the property you need

Create a class with all the property you need that's all
Ex.
  <resultMap id="ridotta" class="ClassName">
    <result column="ID" property="id" jdbcType="INTEGER"/>
    <result column="LOGIN" property="login" jdbcType="VARCHAR"/>
    <result column="SENHA" property="senha" jdbcType="VARCHAR"/>
...
    <result column="EMAIL" property="email" jdbcType="VARCHAR"/>
    <result column=" area.id " property="areaId" jdbcType="INTEGER"/>
    <result column=" area.descricao " property=" descricao "
jdbcType="VARCHAR"/>
  </resultMap>

	select id="getById" parameterClass="java.lang.Integer"
resultClass="Usuario"
		SELECT t1.id, t1.login, t1.senha, t1.grupo, t1.inativo,
t1.nome, t1.depto, t1.cargo, t1.email,
                t2.id as area,
                t2.descricao AS descricao

                FROM usuarios t1, areas t2
                WHERE t1.area = t2.id
                AND t1.id=#id#
...
I use this system and all work fine

Rinaldo

-----Messaggio originale-----
Da: Caio Zanchetti [mailto:caio.zanchetti@gmail.com] 
Inviato: venerdì 27 ottobre 2006 15.20
A: user-java@ibatis.apache.org
Oggetto: Re: R: iBATIS Mapping

Rinaldo, tanks for reply.
I don't understand what exactly is incorrect, can you explain please?
But, anyway, i don't want to have the fields of Area in my Usuario.
Only the object Area. (In Hibernate its possible through the mapping
of a Component).
Any doubt please ask me.
Tanks


On 10/27/06, Rinaldo <rb...@sardiniapoint.it> wrote:
> Hi,
> Control your Usuario class, it's seems that it's not correct
>
> Example
>
> Integer  ID;
> String  LOGIN;
> String  SENHA;
> ...
> String EMAIL;
> Integer areaId;
> String  areaDesc;
>
>
>
> Regards Rinaldo
>
>
>
> -----Messaggio originale-----
> Da: Caio Zanchetti [mailto:caio.zanchetti@gmail.com]
> Inviato: venerdì 27 ottobre 2006 13.21
> A: user-java@ibatis.apache.org
> Oggetto: iBATIS Mapping
>
> Guys, i'm using the ibatis in a project in my company, could you please
help
> me?
>
> The problem consists just in a retrive an object (of type Usuario)
> from the database, this object contains an object of type Area. All
> the others fields are OK (are populated perfectly). Only this object
> (Area) is not instanced (and populated) by ibatis.
>
> This situation happends very similar in the Demo ibatis jPetStore app,
> with the classes Item and Procut. (Product is a field of Item). I
> tryed to follow the same way they used to solve their problems in
> their app.
>
> The mapping and the tables of my app:
>
> PS: The names are in brazilian portuguese:
> Usuario - User
> senha - password
> grupo - group
> nome - name
> depto - dept
> cargo - function
> inativo - inactive
>
> descricao - description (of an area).
>
>
> * My tables:
>
> USUARIO:
>   "ID"   INTEGER NOT NULL,
>   "LOGIN"        VARCHAR(15) NOT NULL,
>   "SENHA"        CHAR(80),
>   "GRUPO"        SMALLINT NOT NULL,
>   "NOME"         VARCHAR(60),
>   "DEPTO"        VARCHAR(20),
>   "CARGO"        VARCHAR(20),
>   "INATIVO"      VARCHAR(1),
>   "EMAIL"        VARCHAR(60),
>   "AREA"         INTEGER,
>
>
> AREA
>   "ID"   INTEGER,
>   "DESCRICAO"    VARCHAR(30)
>    ...
>
>
> * My mapping file (the part where i'm working):
> ...
>         select id="getById" parameterClass="java.lang.Integer"
> resultClass="Usuario"
>                 SELECT usuarios.id, login, senha, grupo, inativo, nome,
> depto, cargo, email,
>                 area AS "area.id",
>                 descricao AS "area.descricao"
>
>                 FROM usuarios, areas
>                 WHERE usuarios.area = areas.id
>                 AND usuarios.id=#id#
> ...
>
>
>
> * The call in the DAO class:
>
>     public Usuario getById(Integer id) {
>         return (Usuario)
> super.getSqlMapClientTemplate().queryForObject("getById", id);
>     }
>
>
> I believe that the POJOS will not necessary because it have only the
> same tables structure.
>
> There are two other solutions that are: Use a map for the return or
> execute 2 selects in my DAO, I don't want to use no one of them.
>
>
> Gratefful,
>
> --
> Claudiomir G. Zanchetti (Caio)
> Sun Certified Programmer for the Java 2 Plataform, Standard Edition 5.0
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.408 / Virus Database: 268.13.14/502 - Release Date:
27/10/2006
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.408 / Virus Database: 268.13.14/502 - Release Date:
27/10/2006
>
>
>
>


-- 
Claudiomir G. Zanchetti (Caio)
Sun Certified Programmer for the Java 2 Plataform, Standard Edition 5.0

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.14/502 - Release Date: 27/10/2006
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.14/502 - Release Date: 27/10/2006
 



Re: R: iBATIS Mapping

Posted by Caio Zanchetti <ca...@gmail.com>.
Rinaldo, tanks for reply.
I don't understand what exactly is incorrect, can you explain please?
But, anyway, i don't want to have the fields of Area in my Usuario.
Only the object Area. (In Hibernate its possible through the mapping
of a Component).
Any doubt please ask me.
Tanks


On 10/27/06, Rinaldo <rb...@sardiniapoint.it> wrote:
> Hi,
> Control your Usuario class, it's seems that it's not correct
>
> Example
>
> Integer  ID;
> String  LOGIN;
> String  SENHA;
> ...
> String EMAIL;
> Integer areaId;
> String  areaDesc;
>
>
>
> Regards Rinaldo
>
>
>
> -----Messaggio originale-----
> Da: Caio Zanchetti [mailto:caio.zanchetti@gmail.com]
> Inviato: venerdì 27 ottobre 2006 13.21
> A: user-java@ibatis.apache.org
> Oggetto: iBATIS Mapping
>
> Guys, i'm using the ibatis in a project in my company, could you please help
> me?
>
> The problem consists just in a retrive an object (of type Usuario)
> from the database, this object contains an object of type Area. All
> the others fields are OK (are populated perfectly). Only this object
> (Area) is not instanced (and populated) by ibatis.
>
> This situation happends very similar in the Demo ibatis jPetStore app,
> with the classes Item and Procut. (Product is a field of Item). I
> tryed to follow the same way they used to solve their problems in
> their app.
>
> The mapping and the tables of my app:
>
> PS: The names are in brazilian portuguese:
> Usuario - User
> senha - password
> grupo - group
> nome - name
> depto - dept
> cargo - function
> inativo - inactive
>
> descricao - description (of an area).
>
>
> * My tables:
>
> USUARIO:
>   "ID"   INTEGER NOT NULL,
>   "LOGIN"        VARCHAR(15) NOT NULL,
>   "SENHA"        CHAR(80),
>   "GRUPO"        SMALLINT NOT NULL,
>   "NOME"         VARCHAR(60),
>   "DEPTO"        VARCHAR(20),
>   "CARGO"        VARCHAR(20),
>   "INATIVO"      VARCHAR(1),
>   "EMAIL"        VARCHAR(60),
>   "AREA"         INTEGER,
>
>
> AREA
>   "ID"   INTEGER,
>   "DESCRICAO"    VARCHAR(30)
>    ...
>
>
> * My mapping file (the part where i'm working):
> ...
>         select id="getById" parameterClass="java.lang.Integer"
> resultClass="Usuario"
>                 SELECT usuarios.id, login, senha, grupo, inativo, nome,
> depto, cargo, email,
>                 area AS "area.id",
>                 descricao AS "area.descricao"
>
>                 FROM usuarios, areas
>                 WHERE usuarios.area = areas.id
>                 AND usuarios.id=#id#
> ...
>
>
>
> * The call in the DAO class:
>
>     public Usuario getById(Integer id) {
>         return (Usuario)
> super.getSqlMapClientTemplate().queryForObject("getById", id);
>     }
>
>
> I believe that the POJOS will not necessary because it have only the
> same tables structure.
>
> There are two other solutions that are: Use a map for the return or
> execute 2 selects in my DAO, I don't want to use no one of them.
>
>
> Gratefful,
>
> --
> Claudiomir G. Zanchetti (Caio)
> Sun Certified Programmer for the Java 2 Plataform, Standard Edition 5.0
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.408 / Virus Database: 268.13.14/502 - Release Date: 27/10/2006
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.408 / Virus Database: 268.13.14/502 - Release Date: 27/10/2006
>
>
>
>


-- 
Claudiomir G. Zanchetti (Caio)
Sun Certified Programmer for the Java 2 Plataform, Standard Edition 5.0

R: iBATIS Mapping

Posted by Rinaldo <rb...@sardiniapoint.it>.
Hi,
Control your Usuario class, it's seems that it's not correct

Example

Integer  ID;
String  LOGIN;
String  SENHA;
...
String EMAIL;
Integer areaId;
String  areaDesc;



Regards Rinaldo



-----Messaggio originale-----
Da: Caio Zanchetti [mailto:caio.zanchetti@gmail.com] 
Inviato: venerdì 27 ottobre 2006 13.21
A: user-java@ibatis.apache.org
Oggetto: iBATIS Mapping

Guys, i'm using the ibatis in a project in my company, could you please help
me?

The problem consists just in a retrive an object (of type Usuario)
from the database, this object contains an object of type Area. All
the others fields are OK (are populated perfectly). Only this object
(Area) is not instanced (and populated) by ibatis.

This situation happends very similar in the Demo ibatis jPetStore app,
with the classes Item and Procut. (Product is a field of Item). I
tryed to follow the same way they used to solve their problems in
their app.

The mapping and the tables of my app:

PS: The names are in brazilian portuguese:
Usuario - User
senha - password
grupo - group
nome - name
depto - dept
cargo - function
inativo - inactive

descricao - description (of an area).


* My tables:

USUARIO:
  "ID"	 INTEGER NOT NULL,
  "LOGIN"	 VARCHAR(15) NOT NULL,
  "SENHA"	 CHAR(80),
  "GRUPO"	 SMALLINT NOT NULL,
  "NOME"	 VARCHAR(60),
  "DEPTO"	 VARCHAR(20),
  "CARGO"	 VARCHAR(20),
  "INATIVO"	 VARCHAR(1),
  "EMAIL"	 VARCHAR(60),
  "AREA"	 INTEGER,


AREA
  "ID"	 INTEGER,
  "DESCRICAO"	 VARCHAR(30)
   ...


* My mapping file (the part where i'm working):
...
	select id="getById" parameterClass="java.lang.Integer"
resultClass="Usuario"
		SELECT usuarios.id, login, senha, grupo, inativo, nome,
depto, cargo, email,
                area AS "area.id",
                descricao AS "area.descricao"

                FROM usuarios, areas
                WHERE usuarios.area = areas.id
                AND usuarios.id=#id#
...



* The call in the DAO class:

    public Usuario getById(Integer id) {
        return (Usuario)
super.getSqlMapClientTemplate().queryForObject("getById", id);
    }


I believe that the POJOS will not necessary because it have only the
same tables structure.

There are two other solutions that are: Use a map for the return or
execute 2 selects in my DAO, I don't want to use no one of them.


Gratefful,

-- 
Claudiomir G. Zanchetti (Caio)
Sun Certified Programmer for the Java 2 Plataform, Standard Edition 5.0

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.14/502 - Release Date: 27/10/2006
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.14/502 - Release Date: 27/10/2006