Announcement Announcement Module
Collapse
No announcement yet.
Problems with inheritance Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with inheritance

    Hello there I have this following scenario:


    Code:
    public abstract class GenericBusinessObject<T, ID extends Serializable> {
        public abstract DAO<T,ID> getDao();
    }
    
    public class AssinanteBO extends GenericBusinessObject<Assinante,AssinantePK> {
    private AssinanteDAO dao;
    	
    	@Override
    	public AssinanteDAO getDao() {
    		return dao;
    	}
    	public void setDao(AssinanteDAO dao) {
    		this.dao = dao;
    	}
    }
    What I'm trying to do here is create a kind of template method for my BO, where The concrete DAO is injected on the concrete class, and some base methods lies on the abstract BO class.

    Well, When injecting the AssinanteDAO using Spring (AssinanteDAO extends DAO) I get an error:
    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pacoteBO' defined in class path resource [conf/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dao' of bean class [com.way.cplus.model.bo.PacoteBO]: Bean property 'dao' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
    org.springframework.beans.NotWritablePropertyException: Invalid property 'dao' of bean class [com.way.cplus.model.bo.PacoteBO]: Bean property 'dao' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
    My guess is that Spring is confused once the parent class getMethod returns a DAO and the override method and the setter on the implementation class return a AssinanteDAO.

    I'm a bit confused here, shouldn't it be trying to use the child class method instead of the parent? Is there an workaround for this?

    Regards

  • #2
    Hi,

    The exception is trying to call com.way.cplus.model.bo.PacoteBO.setDao(), but you don't mention anything about com.way.cplus.model.bo.PacoteBO. Can you please post that code and your entire config

    Comment


    • #3
      The code you show uses covariant return types. I doubt this amounts to a valid JavaBean property. So I think your guess is correct.

      Comment


      • #4
        Originally posted by Rod Johnson
        The code you show uses covariant return types. I doubt this amounts to a valid JavaBean property. So I think your guess is correct.
        Rod,

        Is it possibly for the Spring bean wrapper infrastructure to distinquish between the two scenarios (missing setter v mismatch setter/getter), or does the reflections API (which I assume is being used) not allow that?

        Should I raise this as a JIRA?

        Comment


        • #5
          convariant return types

          hi,

          first of all, Im very impressed by the Spring framework. In particular regarding declarative Transactions ussing @Transactional.

          Anyway, Im facing the same issue (using spring 2.0 rc4) like the user viniciuscarvalho. Im having also the same scenario - DAO return types.

          Will you adress this issue in a future version ?
          Isnt it possible to recognise this case like yatesco suggest?

          thanx,
          Andreas

          Comment

          Working...
          X