ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leandro Saad" <leandro.s...@gmail.com>
Subject Re: use of abstract classes in sqlMap
Date Mon, 09 Oct 2006 13:26:04 GMT
Hi Guido,

iBatis can't tell which subclass of RelationShip you want to create. You can
try to configure the ObjectFactory in sqlMap to achive this behavior.

:: Leandro

On 10/9/06, Guido García Bernardo <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
>

Mime
View raw message