ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Caio Zanchetti" <caio.zanche...@gmail.com>
Subject Re: R: R: iBATIS Mapping
Date Fri, 27 Oct 2006 14:28:07 GMT
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 <rbonazzo@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 <rbonazzo@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

Mime
View raw message