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 Re: use of abstract classes in sqlMap
Date Tue, 10 Oct 2006 16:00:08 GMT
Thank you, Larry.

The reason to use a relationship is that we have three kinds of 
relations between users (each one is stored in a different table).

class Relationship
        |______ class Friendship
        |______ class AAA
        |______ class BBB

The user selects the relation he is interested in, and we always work 
with a Relationship object created by a factory:

    Relationship relation = RelationFactory.create( ... ); // it returns 
a Friendship, AAA or BBB instance.

So when we would like to be able to store it calling a saveRelation( 
Relationship) method ... I'll try to omit the "parameterClass"

Thank you again,
Guido García Bernardo.

Larry Meadors escribió:
> Why would you use a relationship instance to populate a friend table?
> That seems inappropriate.
>
> At any rate, if you ditch the parameter class (it is not required) it 
> will work.
>
> Larry
>
>
> 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
>>
>


-- 
Guido García Bernardo

Tfn. +34 983 54 89 08
ITDEUSTO - Valladolid


Mime
View raw message