ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Butler" <jeffgbut...@gmail.com>
Subject Re: use of abstract classes in sqlMap
Date Tue, 10 Oct 2006 13:21:14 GMT
If you follow Larry's suggestion (remove the parameterClass attribute), then
it will introspect at runtime.  There is some performance hit for doing
this.

Jeff Butler



On 10/10/06, Guido García Bernardo <ggb275@tid.es> wrote:
>
> Why not to introspect the classes at runtime (or to add a parameter to
> configure it) ?
> Thank you.
>
> Jeff Butler escribió:
> > iBATIS introspects classes at initialization time.  You've configured
> > iBATIS to think that the Relationship class has a comment property
> > - which it doesn't.
> >
> > If you want to have iBATIS introspect with every statement, then you
> > can use a Map instead of a JavaBean.
> >
> > You could also add abstract getComment, setComment methods to your
> > Relationship class.
> >
> > Jeff Butler
> >
> >
> > On 10/9/06, *Guido García Bernardo* <ggb275@tid.es
> > <mailto:ggb275@tid.es>> wrote:
> >
> >     Imagine the following abstract class:
> >
> >     public abstract class Relationship {
> >         private String dateRelation;
> >         private Integer idUser;
> >         // getters & setters
> >     }
> >
> >     That allows to define several kinds of relations, i.e:
> >
> >     public class Friendship extends Relationship {
> >         private String comment;
> >         // getters & setters
> >     }
> >
> >     The SQL map:
> >
> >         <sqlMap>
> >             <typeAlias alias="relation" type="my.package.Relationship"
> />
> >
> >             <insert id="insertFriend" parameterClass="relation">
> >                 insert into FRIENDS ( id_user, date_relation, comment )
> >                 values ( #idUser#, #dateRelation#, #comment# )
> >             </insert>
> >         </sqlMap>
> >
> >     And my ibatis code throws a message error "There is not readable
> >     property 'comment' in my.package.Relationship".
> >
> >         Relationship friend = new Friendship( ... );
> >         saveRelation( friend );
> >         ...
> >
> >         public void saveRelation(Relationship relation) throws
> >     DAOException {
> >             try {
> >                 if (relation instanceof Friendship) {
> >                     getSqlMapExecutor().insert( "insertFriend",
> >     relation );
> >                 } else if ...
> >                 ...
> >             } catch (SQLException e) {
> >                 throw new DAOException( "Error saving friend", e );
> >             }
> >         }
> >
> >     Why ibatis does not discover object properties at runtime? Is
> >     there any way to use abstract classes in my sql-map files?
> >     I am not sure if I have explained my problem properly...
> >
> >     Thank you very much.
> >     Guido García Bernardo
> >
> >
> >
>
>
> --
> Guido García Bernardo
>
> Tfn. +34 983 54 89 08
> ITDEUSTO - Valladolid
>
>

Mime
View raw message