You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Guido García Bernardo <gg...@tid.es> on 2006/10/09 13:58:43 UTC
use of abstract classes in sqlMap
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
Re: use of abstract classes in sqlMap
Posted by Jeff Butler <je...@gmail.com>.
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 <gg...@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
> > <ma...@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
>
>
Re: use of abstract classes in sqlMap
Posted by Guido García Bernardo <gg...@tid.es>.
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
> <ma...@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
Re: use of abstract classes in sqlMap
Posted by Jeff Butler <je...@gmail.com>.
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 <gg...@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
>
>
Re: use of abstract classes in sqlMap
Posted by Leandro Saad <le...@gmail.com>.
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 <gg...@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
>
Re: use of abstract classes in sqlMap
Posted by Guido García Bernardo <gg...@tid.es>.
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 <gg...@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
Re: use of abstract classes in sqlMap
Posted by Larry Meadors <lm...@apache.org>.
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 <gg...@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
>