Announcement Announcement Module
Collapse
No announcement yet.
Setting EntityManagerFactory into Neo4J config getting NotWritablePropertyException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting EntityManagerFactory into Neo4J config getting NotWritablePropertyException

    Caused by: org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'entityManagerFactory' of bean class [org.springframework.data.neo4j.config.Neo4jConfigu ration$$EnhancerByCGLIB$$fef67448]: 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?



    Not sure how to solve this.

    It might be related to the version I am using

    SDN version: 2.1.0.RC3

    Thanks

    Mark

  • #2
    It is usually autowired in the CrossStoreConfig? What does your setup look like?

    Comment


    • #3
      This is our xml config. Which also by the way, I have a property placeholder for .properties file that also doesn't work, when it should. So I have been putting the values in the .properties directly into the xml, but changed it back to hide those values for now.

      Code:
          
          <jdbc:embedded-database id="dataSource">
              <jdbc:script location="classpath:sqlscripts/create-account-tables.sql"/>
              <jdbc:script location="classpath:sqlscripts/create-account-data.sql"/>
          </jdbc:embedded-database>
      
          <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
              <property name="dataSource" ref="dataSource"/>
              <property name="jpaVendorAdapter" ref="jpaAdapter"/>
              <property name="loadTimeWeaver">
                  <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
              </property>
              <property name="persistenceUnitName" value="testing"/>
              <property name="packagesToScan">
                  <list>
                      <value>com.hdpoker.account.domain</value>
                  </list>
              </property>
          </bean>
      
          <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
              <property name="entityManagerFactory" ref="entityManagerFactory"/>
          </bean>
      
          <bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
              <property name="database" value="HSQL"/>
              <property name="showSql" value="true"/>
              <property name="generateDdl" value="false"/>
          </bean>
      
          <context:property-placeholder location="classpath:META-INF/spring/neo4j.properties"/>
      
          <neo4j:config storeDirectory="${neo4j.location}" entityManagerFactory="entityManagerFactory"/>
          
          <neo4j:repositories base-package="${neo4j.basepackage}"/>
      As you can see at the end I use the entityManagerFactory attribute of the neo4j:config tag. I believe that in the lifecyle of Spring that tag and attribute then tries to call a method setEntityManagerFactory on the Configuration class, and there is no such method in current version of SDN. It was in the 1.0.x versions.

      Thanks

      Mark

      Comment


      • #4
        In the end, I think it was version conflicts.

        I moved all my Spring Data dependency to RELEASE versions commons 1.4.0 JPA 1.2.0, Neo 2.1.0 and I don't get that error.

        But I still have an issue now with connecting to the database.

        Code:
        java.lang.IllegalStateException: Failed to load ApplicationContext
        	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
        	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
        	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
        	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
        	at org.spockframework.spring.SpringTestContextManager.prepareTestInstance(SpringTestContextManager.java:49)
        	at org.spockframework.spring.SpringInterceptor.interceptSetupMethod(SpringInterceptor.java:42)
        	at org.spockframework.runtime.extension.AbstractMethodInterceptor.intercept(AbstractMethodInterceptor.java:28)
        	at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:84)
        	at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:138)
        	at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:138)
        	at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:138)
        	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
        	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
        Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.neo4j.config.Neo4jConfiguration#0': Cannot resolve reference to bean 'graphDatabaseService' while setting bean property 'graphDatabaseService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphDatabaseService': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.neo4j.kernel.EmbeddedGraphDatabase]: Constructor threw exception; nested exception is java.lang.NullPointerException
        	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
        	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
        	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
        	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:353)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1015)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
        	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
        	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:605)
        	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)
        	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
        	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
        	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
        	at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
        	at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
        	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
        	... 15 more
        Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphDatabaseService': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.neo4j.kernel.EmbeddedGraphDatabase]: Constructor threw exception; nested exception is java.lang.NullPointerException
        	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:288)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
        	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
        	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
        	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)
        	... 41 more
        Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.neo4j.kernel.EmbeddedGraphDatabase]: Constructor threw exception; nested exception is java.lang.NullPointerException
        	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162)
        	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:121)
        	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280)
        	... 50 more
        Caused by: java.lang.NullPointerException
        	at java.io.File.<init>(File.java:251)
        	at org.neo4j.kernel.AbstractGraphDatabase.canonicalize(AbstractGraphDatabase.java:1034)
        	at org.neo4j.kernel.AbstractGraphDatabase.<init>(AbstractGraphDatabase.java:203)
        	at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:77)
        	at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:70)
        	at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:55)
        	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
        	... 52 more

        Comment


        • #5
          Just add a javaconfig defining a Config with a bean:

          Code:
          @Bean GraphDatabaseService graphDatabaseService() {
             return new EmbeddedGraphDatabase(path);
          }

          Comment


          • #6
            OK, resolved that.

            But now I am back to getting the original error in this thread.

            Caused by: org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'entityManagerFactory' of bean class

            Mark

            Comment


            • #7
              Using the CrossStoreNeo4jConfiguration class I can now set the entityManagerFactory.

              Had to add spring-data-neo4j-cross-store jar to my project.

              Mark

              Comment

              Working...
              X