Results 1 to 7 of 7

Thread: Type Mismatch

  1. #1
    Join Date
    Jun 2006
    Location
    Rome,Italy
    Posts
    27

    Question Type Mismatch

    Do you see any mistake in this piece of code?

    This is my netbeans error message:
    Code:
    Error creating bean with name 'facadeAvvisi' defined in file [...\web\WEB-INF\applicationContext.xml]: Error setting property values;
     nested exception is org.springframework.beans.NotWritablePropertyException:
     Invalid property 'aDao' of bean class [...sistema.FacadeAvvisi]:
     Bean property 'aDao' is not writable or has an invalid setter method:
     Does the parameter type of the setter match the return type of the getter?
    this is a piece of the ApplicationContext.xml:

    Code:
    <bean id="facadeAvvisi" class="org.apache.shale.progettotesi.sistema.FacadeAvvisi">
            <property name="aDao">
                <ref bean="avvisoDao"></ref>
            </property>
    </bean>
    
    ...
    
    <bean id="avvisoDao" class="org.apache.shale.progettotesi.persistenza.impl.AvvisoDaoImpl">
            <property name="dataSource">
                <ref bean="dataSource"></ref>
            </property>
    </bean>
    and these are my java class(only a piece..):

    Code:
    public class FacadeAvvisi{
    
    private AvvisoDao aDao;
    //getter and setter
    }
    
    public interface AvvisoDao {
        ...
    }
    
    public class AvvisoDaoImpl extends JdbcDaoSupport implements AvvisoDao, RowCallbackHandler{
    ...
    }
    It seems that there is a type mismatch between the property in the AppContext.xml and the java variable.But actually it isn't..

    thanks 4 help

  2. #2
    Join Date
    May 2006
    Location
    Darmstadt - Germany
    Posts
    142

    Default

    can u post the setter?
    When i have an apple and you have an apple and we change them, we both continue with one apple.
    When i have an idea and you have an idea and we change them, we both will have two ideas.

  3. #3
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    You left out the interesting part

    Can you post the getter and setter of the Dao?

    Regards,
    Andreas

  4. #4
    Join Date
    Jun 2006
    Location
    Rome,Italy
    Posts
    27

    Default

    this are getter/setter of facadeAvvisi:

    Code:
    public class FacadeAvvisi {
        
        private AvvisoDao aDao;
    ..
    public AvvisoDao getADao() {
            return aDao;
        }
    
        public void setADao(AvvisoDao aDao) {
            this.aDao = aDao;
        }
    ..
    }

  5. #5
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    That's a special case of the JavaBeans specification. Normally, if you have a property named "dao", the according setter will be "setDao" (note the case).
    If, however, a property name starts with two uppercase letters, then it stands as is. So for your case, the correct property name (matching your getter/setter) is "ADao". Take this as name in your app context file, and things should work.

    Regards,
    Andreas

  6. #6
    Join Date
    Jun 2006
    Location
    Rome,Italy
    Posts
    27

    Thumbs up



    thanks 4 help

  7. #7
    Join Date
    May 2006
    Location
    Darmstadt - Germany
    Posts
    142

    Default

    or:
    Code:
    public class FacadeAvvisi {
        
        private AvvisoDao avvisoDao;
    ..
    public AvvisoDao getAvvisoDao() {
            return avvisoDao;
        }
    
        public void setAvvisoDao(AvvisoDao aDao) {
            this.avvisoDao = aDao;
        }
    ..
    }
    and
    Code:
    <bean id="facadeAvvisi" class="org.apache.shale.progettotesi.sistema.FacadeAvvisi">
            <property name="avvisoDao">
                <ref bean="avvisoDao"></ref>
            </property>
    </bean>
    When i have an apple and you have an apple and we change them, we both continue with one apple.
    When i have an idea and you have an idea and we change them, we both will have two ideas.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •