ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zoran Avtarovski <zo...@sparecreative.com>
Subject Re: M:N solution and populating arrays instead of List
Date Mon, 27 Mar 2006 23:12:17 GMT
Hi Raul,

I'm not sure if it's the best way, but we had the same requirements and were
able to do it by setting some extra getter and setter methods in the in our
Java object.

In you your example for instance to return an array we would set a getter
called getReclamationArray() and convert the List to an array on the fly and
return that. If you need an array setter do the same thing and convert the
array to a list in the setter method.

Thinking about about it it doesn't matter if you use the above approach or
the manipulate the List getter and setter to convert to an Array as long as
you're consistent.

With regards to null values we do null checks on key fields and ignore the
object if it is null. This introduces a small overhead, but we've found that
it had negligible impact on performance.

I hope that's clear, sort of.


Zoran

> Hi to all.
> 
>  
> 
> I have a Infracction Class with a List field called reclamacion wich is to be
> populated with objects of Reclamation type, using the 1:N & N:M solution for
> N+1 querys i´m able to populate this property with a simple query. Here the
> code I use:
> 
>  
> 
> public class Infraction extends BaseObject {
> 
>             private static final long serialVersionUID = 1L;
> 
>  
> 
>             private Integer idInfraccion;
> 
>  
> 
>             private java.lang.String codExpediente;
> 
>                                    .
> 
>  
> 
>                                    .
> 
>  
> 
>                                    .
> 
>                                    .
> 
>             private List reclamation;
> 
> }
> 
>  
> 
> With corresponding getters and setters
> 
>  
> 
> Reclamation class is a javabean
> 
>  
> 
> Here´s my sqlMap config file for Infraction:
> 
>  
> 
> <resultMap id="infraccionMapaReclamaciones"
> class="com.amap.multas.model.Infraction" extends="infractionMapa"
> groupBy="idInfraction">
> 
>                         <result property="reclamacion"
> resultMap="Reclamation.reclamacionMapa" "/>
> 
> </resultMap>
> 
>  
> 
> <select id="findByPrimaryKeyWithReclamacion"
> resultMap="infraccionMapaReclamaciones" parameterClass="infraccion">
> 
>                         SELECT * FROM INFRACCION LEFT JOIN RECLAMACION ON
> 
>                  
> INFRACCION.ID_INFRACCION=RECLAMACION.ID_INFRACCION
> 
>                         WHERE INFRACCION.ID_INFRACCION=#idInfraccion#
> 
> </select>
> 
>  
> 
> The only problem i have with this approach is that it always creates the
> Reclamation List with at least one element with all fields with null value,
> but the List is there.
> 
>  I would like this List to be null, a TypeHandler for this property dosen´t
> seem to work because Ibatis don´t set the List directly but it  makes calls to
> getReclamation().add(Object) instead.
> 
> Anyone knows a solution for this issue apart from a manual parsing of the List
> after ibatis?  
> 
>  
> 
> Apart of that, now my boss want me to change the reclamacion field´s type from
> List to Reclamacion[] and the above solution didn´t work because Ibatis seems
> to not support arrays as types to populate. I ´ve search the documentation and
> mailing list and all point to that. I have ways to overcome this, creating a
> subclass of Infraction with List instead of array and use it only from Ibatis,
> a getter method to transform and so on.
> 
> But I would like to be sure there´s no way to do this from Ibatis before doing
> that, custom TypeHandler seems not to be the solution because Ibatis don´t set
> a List directly, so...
> 
> There´s some way to accomplish this using Ibatis?
> 
>  
> 
> Thanks in advance and sorry for the long post and poor english.
> 
>  
> 
> Raúl Arabaolaza 
> 
>  
> 
>  
> 
>  
> 
>  
> 



Mime
View raw message