Announcement Announcement Module
Collapse
No announcement yet.
Bean property 'entityManagerFactory' is not writable Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean property 'entityManagerFactory' is not writable

    Hello

    I am getting the following error while deploying my application

    "org.springframework.beans.NotWritablePropertyExce ption: Invalid property 'entityManagerFactory' of bean class [com.barclayswealth.minerva.dao.AccountDaoJPAImpl]: Bean property 'entityManagerFactory' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?"

    My persistence.xml
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">

    <persistence-unit name="MySpring" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence </provider>
    <properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
    <property name="hibernate.show_sql" value="true"/>
    <property name="hibernate.generate_statistics" value="true"/>
    <property name="hibernate.hbm2ddl.auto" value="update"/>
    <property name="hibernate.jdbc.batch_size" value="10"/>
    </properties>
    </persistence-unit>

    </persistence>

    application context
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="persistenceUnitName" value="MySpring"/>
    <property name="dataSource" ref="dataSource"/>
    </bean>


    My JPADAOIMPL class

    @Transactional
    public class AccountDaoJPAImpl extends HibernateDaoSupport implements AccountDao {
    private EntityManager em;

    // Spring will inject this:
    @PersistenceContext
    public void setEntityManager(EntityManager em) {
    this.em = em;
    }

    i am using the following jar files
    persistence.jar, hibernate-entitymanager.jar, jboss-archive-browsing.jar, hibernate3.jar

  • #2
    The exception message is quite clear IMHO.


    "org.springframework.beans.NotWritableProperty Exce ption: Invalid property 'entityManagerFactory' of bean class [com.barclayswealth.minerva.dao.AccountDaoJPAImpl]: Bean property 'entityManagerFactory' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?"
    Your bean doesn't have a setEntityManagerFactory method...

    Please next time when posting code use [ code][/code ] tags!

    Comment


    • #3
      Hello,

      after the setEntityManagerFactory, i am getting the following error


      Code:
      ERROR [org.springframework.web.context.ContextLoader] Context initialization failed
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountService' defined in ServletContext resource [/WEB-INF/applicationContext-jpa.xml]: Cannot resolve reference to bean 'accountDao' while setting bean property 'accountDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountDao' defined in ServletContext resource [/WEB-INF/applicationContext-jpa.xml]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.PersistenceContext.properties()[Ljavax/persistence/PersistenceProperty;
      Caused by: 
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountDao' defined in ServletContext resource [/WEB-INF/applicationContext-jpa.xml]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.PersistenceContext.properties()[Ljavax/persistence/PersistenceProperty;
      Caused by: 
      java.lang.NoSuchMethodError: javax.persistence.PersistenceContext.properties()[Ljavax/persistence/PersistenceProperty;
      	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.addIfPresent(PersistenceAnnotationBeanPostProcessor.java:285)

      Comment


      • #4
        Do you have the correct jpa-api in your classpath? Try the one supplied with Spring.

        Comment


        • #5
          i am using persistence.jar file

          is there any jpa-api.jar file ?

          Comment


          • #6
            the application was having both
            persistence.jar and ejb3-persistence.jar files

            i have removed ejb3-persistence.jar file from class path

            so now i have the following error


            Code:
            ERROR [org.springframework.web.context.ContextLoader] Context initialization failed
            org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountService' defined in ServletContext resource [/WEB-INF/applicationContext-jpa.xml]: Cannot resolve reference to bean 'accountDao' while setting bean property 'accountDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountDao' defined in ServletContext resource [/WEB-INF/applicationContext-jpa.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
            PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0] to required type [javax.persistence.EntityManager] for property 'entityManagerFactory'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0] to required type [javax.persistence.EntityManager] for property 'entityManagerFactory': no matching editors or conversion strategy found
            Caused by: 
            org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountDao' defined in ServletContext resource [/WEB-INF/applicationContext-jpa.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
            PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0] to required type [javax.persistence.EntityManager] for property 'entityManagerFactory'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0] to required type [javax.persistence.EntityManager] for property 'entityManagerFactory': no matching editors or conversion strategy found
            Caused by: 
            org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessException details (1) are:
            PropertyAccessException 1:
            org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0] to required type [javax.persistence.EntityManager] for property 'entityManagerFactory'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0] to required type [javax.persistence.EntityManager] for property 'entityManagerFactory': no matching editors or conversion strategy found
            Caused by: 
            java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0] to required type [javax.persistence.EntityManager] for property 'entityManagerFactory': no matching editors or conversion strategy found
            	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:225)
            	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:139)
            	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:771)
            	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:604)
            	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValue(AbstractPropertyAccessor.java:49)
            	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:74)
            	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
            	at org.springframework.beans.factory.support.AbstractBeanFactory.applyPropertyValues(AbstractBeanFactory.java:852)
            	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1054)

            Comment


            • #7
              exactly the same problem

              I have exactly the same problem youe have. Have anybody already find a solution for this issue?

              kind regards
              René Gröschke

              Comment


              • #8
                If you review the javadoc for EntityManagerFactoryBean you will see it creates an EntityManagerFactory, not an EntityManager

                Have you read http://static.springframework.org/sp...pa-setup-lemfb

                Comment


                • #9
                  yes I read it

                  ...but I think I read over some lines.

                  thanks a lot.

                  Comment


                  • #10
                    no worries so is it working now?

                    Comment


                    • #11
                      yes it is

                      yes colin, it works it works fine so far. thanks for the help.

                      regards,
                      rene

                      Comment


                      • #12
                        I ask your support and help for this error when installing Alfresco CommunityEdition 2.1
                        ---
                        org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'failOn
                        Error' of bean class [org.alfresco.util.exec.RuntimeExecBootstrapBean]: Bean pro
                        perty 'failOnError' is not writable or has an invalid setter method. Does the pa
                        rameter type of the setter match the return type of the getter?
                        at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrappe
                        rImpl.java:748)
                        at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrappe
                        rImpl.java:606)
                        at org.springframework.beans.AbstractPropertyAccessor .setPropertyValue(A
                        bstractPropertyAccessor.java:49)
                        at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(
                        AbstractPropertyAccessor.java:74)
                        at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(
                        AbstractPropertyAccessor.java:57)
                        at org.springframework.beans.factory.support.Abstract BeanFactory.applyPr
                        opertyValues(AbstractBeanFactory.java:840)
                        at org.springframework.beans.factory.support.Abstract AutowireCapableBean
                        Factory.applyPropertyValues(AbstractAutowireCapabl eBeanFactory.java:1026)
                        at org.springframework.beans.factory.support.Abstract AutowireCapableBean
                        Factory.populateBean(AbstractAutowireCapableBeanFa ctory.java:809)
                        at org.springframework.beans.factory.support.Abstract AutowireCapableBean
                        Factory.createBean(AbstractAutowireCapableBeanFact ory.java:425)
                        at org.springframework.beans.factory.support.Abstract BeanFactory$1.getOb
                        ject(AbstractBeanFactory.java:250)
                        at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistr
                        y.getSingleton(DefaultSingletonBeanRegistry.java:1 41)
                        at org.springframework.beans.factory.support.Abstract BeanFactory.getBean
                        (AbstractBeanFactory.java:247)
                        at org.springframework.beans.factory.support.Abstract BeanFactory.getBean
                        (AbstractBeanFactory.java:161)
                        at org.springframework.beans.factory.support.DefaultL istableBeanFactory.
                        getBeansOfType(DefaultListableBeanFactory.java:236 )
                        at org.springframework.context.support.AbstractApplic ationContext.getBea
                        nsOfType(AbstractApplicationContext.java:701)
                        at org.springframework.context.support.AbstractApplic ationContext.regist
                        erListeners(AbstractApplicationContext.java:519)
                        at org.springframework.context.support.AbstractApplic ationContext.refres
                        h(AbstractApplicationContext.java:343)
                        at org.springframework.web.context.support.AbstractRe freshableWebApplica
                        tionContext.refresh(AbstractRefreshableWebApplicat ionContext.java:156)


                        ---
                        I tried to resolve but I can't understand the problem and I can't continue the work to analyze this tool required for a project and I am under pressure from my bos

                        Please give me any tips to continue the installation of this package.
                        Thank you in advance

                        Rob

                        Comment

                        Working...
                        X