ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guido García Bernardo <ggb...@tid.es>
Subject use of abstract classes in sqlMap
Date Mon, 09 Oct 2006 11:58:43 GMT
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