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 Paul Benedict <pa...@yahoo.com> on 2006/07/11 06:30:47 UTC

interface property predicaments

I have two interfaces: Article and Person. My problem is with my Article implementation:

public interface Article {
  public Person getPerson();
}

public class ArticleImpl extends Article {
  private Person person;
  public Person getPerson() {
    return person;
  }
  public void setPerson(Person person) {
    this.person = person;
  }
  // required for ibatis object construction
  public void setPerson(PersonImpl person) {
     this.person = person;
   }
 }

I am using ibatis to construct it as follows:

<resultMap id="articleMap" class="Article">
    <result property="person.id" column="person_id" />
</resultMap>

I get that annoying "cannot find WRITABLE property id in Person" message because it is looks at Article.getPerson() which returns the interface not implementation. But why should that matter? This is wrong behavior, imo. I know ibatis constructs the inner object first. It will create a PersonImpl, set property "id" from column "person_id", and then call the setter on Article. 

Otherwise, I am left believing ibatis cannot work with classes which need to implement a read-only interface..... or someone can recommend the solution, which I might be unable to find?

Paul

 		
---------------------------------
How low will we go? Check out Yahoo! Messenger’s low  PC-to-Phone call rates.

Re: interface property predicaments

Posted by Vadim Grinshpun <va...@ll.mit.edu>.
Well, here's an example of when you'd want to separate the interface 
from the implementation.
Suppose I need to support lazy loading. (I know iBATIS has some way to 
do this, but it is currently not really documented, so I'd rather roll 
my own for now). A simple way to do this is to store keys for the 
lazily-loaded bits in the bean for later use. However, I would not want 
to expose those properties to the outside world, so I'd only have them 
in the implementation class, keeping the interface clean. Wouldn't you 
say this is a valid use of interfaces?

And yes, I've run into the same problem as Paul... haven't really found 
a clean workaround for it yet. I do believe this is a bug in iBATIS, 

-Vadim



Larry Meadors wrote:
> So...I do not understand..your beans are interfaces?
>
> How often do you swap out the implementation of your beans? ;-)
>
> Larry
>
>
> On 7/10/06, Paul Benedict <pa...@yahoo.com> wrote:
>> I have two interfaces: Article and Person. My problem is with my Article
>> implementation:
>>
>> public interface Article {
>>   public Person getPerson();
>> }
>>
>> public class ArticleImpl extends Article {
>>   private Person person;
>>   public Person getPerson() {
>>     return person;
>>   }
>>   public void setPerson(Person person) {
>>     this.person = person;
>>   }
>>   // required for ibatis object construction
>>   public void setPerson(PersonImpl person) {
>>      this.person = person;
>>    }
>>  }
>>
>> I am using ibatis to construct it as follows:
>>
>> <resultMap id="articleMap" class="Article">
>>     <result property="person.id" column="person_id" />
>> </resultMap>
>>
>> I get that annoying "cannot find WRITABLE property id in Person" message
>> because it is looks at Article.getPerson() which returns the 
>> interface not
>> implementation. But why should that matter? This is wrong behavior, 
>> imo. I
>> know ibatis constructs the inner object first. It will create a 
>> PersonImpl,
>> set property "id" from column "person_id", and then call the setter on
>> Article.
>>
>> Otherwise, I am left believing ibatis cannot work with classes which 
>> need to
>> implement a read-only interface..... or someone can recommend the 
>> solution,
>> which I might be unable to find?
>>
>> Paul
>>
>>
>>  ________________________________
>> How low will we go? Check out Yahoo! Messenger's low PC-to-Phone call 
>> rates.
>>
>>
>


Re: interface property predicaments

Posted by Larry Meadors <lm...@apache.org>.
Why does iBATIS need to know anything about the interface?

Larry


On 7/11/06, Paul Benedict <pa...@yahoo.com> wrote:
> Larry, I am implementing an API. So this is the problem I have to deal with
> :-(
>
> The other guy is right. Ibatis thinks there is no setId on the Person
> because Person interface is read-only, although in the sqlmap I am
> constructing a PersonImpl on an ArticleImpl.
>
> I believe ibatis can be changed to solve this problem: Assuming that ibatis
> constructs inner objects as it navigates (does it?), it should use the
> instance it creates rather than looking at the type from the getter.
>
> Otherwise I will have to have a diferent getter on my object just for ibatis
> that returns the impl.
>
> Paul
>
>
> Larry Meadors <lm...@apache.org> wrote:
>
>  So...I do not understand..your beans are interfaces?
>
> How often do you swap out the implementation of your beans? ;-)
>
> Larry
>
>
> On 7/10/06, Paul Benedict wrote:
> > I have two interfaces: Article and Person. My problem is with my Article
> > implementation:
> >
> > public interface Article {
> > public Person getPerson();
> > }
> >
> > public class ArticleImpl extends Article {
> > private Person person;
> > public Person getPerson() {
> > return person;
> > }
> > public void setPerson(Person person) {
> > this.person = person;
> > }
> > // required for ibatis object construction
> > public void setPerson(PersonImpl person) {
> > this.person = person;
> > }
> > }
> >
> > I am using ibatis to construct it as follows:
> >
> >
> >
> >
> >
> > I get that annoying "cannot find WRITABLE property id in Person" message
> > because it is looks at Article.getPerson() which returns the interface not
> > implementation. But why should that matter? This is wrong behavior, imo. I
> > know ibatis constructs the inner object first. It will create a
> PersonImpl,
> > set property "id" from column "person_id", and then call the setter on
> > Article.
> >
> > Otherwise, I am left believing ibatis cannot work with classes which need
> to
> > implement a read-only interface..... or someone can recommend the
> solution,
> > which I might be unable to find?
> >
> > Paul
> >
> >
> > ________________________________
> > How low will we go? Check out Yahoo! Messenger's low PC-to-Phone call
> rates.
> >
> >
>
>
>
>
>  ________________________________
> Do you Yahoo!?
>  Next-gen email? Have it all with the all-new Yahoo! Mail Beta.
>
>

Re: interface property predicaments

Posted by Paul Benedict <pa...@yahoo.com>.
Larry, I am implementing an API. So this is the problem I have to deal with :-(

The other guy is right. Ibatis thinks there is no setId on the Person because Person interface is read-only, although in the sqlmap I am constructing a PersonImpl on an ArticleImpl. 

I believe ibatis can be changed to solve this problem: Assuming that ibatis constructs inner objects as it navigates (does it?), it should use the instance it creates rather than looking at the type from the getter.

Otherwise I will have to have a diferent getter on my object just for ibatis that returns the impl.

Paul

Larry Meadors <lm...@apache.org> wrote: So...I do not understand..your beans are interfaces?

How often do you swap out the implementation of your beans? ;-)

Larry


On 7/10/06, Paul Benedict 
 wrote:
> I have two interfaces: Article and Person. My problem is with my Article
> implementation:
>
> public interface Article {
>   public Person getPerson();
> }
>
> public class ArticleImpl extends Article {
>   private Person person;
>   public Person getPerson() {
>     return person;
>   }
>   public void setPerson(Person person) {
>     this.person = person;
>   }
>   // required for ibatis object construction
>   public void setPerson(PersonImpl person) {
>      this.person = person;
>    }
>  }
>
> I am using ibatis to construct it as follows:
>
> 
>     
> 
>
> I get that annoying "cannot find WRITABLE property id in Person" message
> because it is looks at Article.getPerson() which returns the interface not
> implementation. But why should that matter? This is wrong behavior, imo. I
> know ibatis constructs the inner object first. It will create a PersonImpl,
> set property "id" from column "person_id", and then call the setter on
> Article.
>
> Otherwise, I am left believing ibatis cannot work with classes which need to
> implement a read-only interface..... or someone can recommend the solution,
> which I might be unable to find?
>
> Paul
>
>
>  ________________________________
> How low will we go? Check out Yahoo! Messenger's low PC-to-Phone call rates.
>
>



 		
---------------------------------
Do you Yahoo!?
 Next-gen email? Have it all with the  all-new Yahoo! Mail Beta.

Re: interface property predicaments

Posted by Larry Meadors <lm...@apache.org>.
So...I do not understand..your beans are interfaces?

How often do you swap out the implementation of your beans? ;-)

Larry


On 7/10/06, Paul Benedict <pa...@yahoo.com> wrote:
> I have two interfaces: Article and Person. My problem is with my Article
> implementation:
>
> public interface Article {
>   public Person getPerson();
> }
>
> public class ArticleImpl extends Article {
>   private Person person;
>   public Person getPerson() {
>     return person;
>   }
>   public void setPerson(Person person) {
>     this.person = person;
>   }
>   // required for ibatis object construction
>   public void setPerson(PersonImpl person) {
>      this.person = person;
>    }
>  }
>
> I am using ibatis to construct it as follows:
>
> <resultMap id="articleMap" class="Article">
>     <result property="person.id" column="person_id" />
> </resultMap>
>
> I get that annoying "cannot find WRITABLE property id in Person" message
> because it is looks at Article.getPerson() which returns the interface not
> implementation. But why should that matter? This is wrong behavior, imo. I
> know ibatis constructs the inner object first. It will create a PersonImpl,
> set property "id" from column "person_id", and then call the setter on
> Article.
>
> Otherwise, I am left believing ibatis cannot work with classes which need to
> implement a read-only interface..... or someone can recommend the solution,
> which I might be unable to find?
>
> Paul
>
>
>  ________________________________
> How low will we go? Check out Yahoo! Messenger's low PC-to-Phone call rates.
>
>

Re: interface property predicaments

Posted by Graeme J Sweeney <ib...@gjsweeney.com>.
On Mon, 10 Jul 2006, Paul Benedict wrote:

> I get that annoying "cannot find WRITABLE property id in Person" message because it is looks at Article.getPerson() which returns the interface not  implementation.

Doesn't that mean that Person is not a JavaBean i.e. missing a setId 
method?

-- 
Graeme -

Re: interface property predicaments

Posted by Paul Benedict <pa...@yahoo.com>.
One thing I forgot to mention: the "Article" class listed in my sqlmap is a typeAlias to the actual implementation. Don't think I am trying to construct an interface :-)

Paul Benedict <pa...@yahoo.com> wrote: I have two interfaces: Article and Person. My problem is with my Article implementation:

public interface Article {
  public Person getPerson();
}

public class ArticleImpl extends Article {
  private Person person;
  public Person getPerson() {
    return person;
  }
  public void setPerson(Person person) {
    this.person = person;
  }
  // required for ibatis object construction
  public void setPerson(PersonImpl person) {
     this.person = person;
   }
 }

I am using ibatis to construct it as follows:

<resultMap id="articleMap" class="Article">
    <result property="person.id" column="person_id" />
</resultMap>

I get that annoying "cannot find WRITABLE property id in Person" message because it is looks at Article.getPerson() which returns the interface not  implementation. But why should that matter? This is wrong behavior, imo. I know ibatis constructs the inner object first. It will create a PersonImpl, set property "id" from column "person_id", and then call the setter on Article. 

Otherwise, I am left believing ibatis cannot work with classes which need to implement a read-only interface..... or someone can recommend the solution, which I might be unable to find?

Paul
    

---------------------------------
How low will we go? Check out Yahoo! Messenger’s low  PC-to-Phone call rates.

 		
---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.