Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Bean property 'entityManagerFactory' is not writable

  1. #1
    Join Date
    Jul 2007
    Posts
    5

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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!
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jul 2007
    Posts
    5

    Default

    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)

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Do you have the correct jpa-api in your classpath? Try the one supplied with Spring.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Jul 2007
    Posts
    5

    Default

    i am using persistence.jar file

    is there any jpa-api.jar file ?

  6. #6
    Join Date
    Jul 2007
    Posts
    5

    Default

    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)

  7. #7
    Join Date
    Aug 2007
    Location
    lake of constance
    Posts
    7

    Default 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

  8. #8
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    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
    Colin Yates
    SpringSource - http://www.springsource.com - Spring Training, Consulting, and Support - "From the Source"
    Please read http://www.springframework.org/documentation
    Co-Author of Expert Spring MVC + Web Flow.

  9. #9
    Join Date
    Aug 2007
    Location
    lake of constance
    Posts
    7

    Smile yes I read it

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

    thanks a lot.

  10. #10
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    no worries so is it working now?
    Colin Yates
    SpringSource - http://www.springsource.com - Spring Training, Consulting, and Support - "From the Source"
    Please read http://www.springframework.org/documentation
    Co-Author of Expert Spring MVC + Web Flow.

Posting Permissions

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