Results 1 to 3 of 3

Thread: entityStateFactory not set when saving from within @PostConstruct

  1. #1
    Join Date
    Mar 2011
    Posts
    8

    Default SDG: entityStateFactory not set when saving from within @PostConstruct

    Hello everybody

    When I try to call save(MyEntity) on the MyEntityRepository as follows,

    Code:
    @NodeEntity
    public class MyEntity {
      //setter and getter for a property called 'name'
    }
    
    public class MyEntityRepository extends GraphRepository<MyEntity> {
    }
    
    public class DbInitialization {
     @Autowired
     private MyEntityRepository repository;
     
     @PostConstruct
     public void initDb() {
      MyEntity entity = MyEntity.newInstance();
      entity.setName("foo");
      repository.save(entity);
     }
    }
    ... I run into the following error:

    Code:
    org.springframework.data.neo4j.support.node.Neo4jNodeBacking      entityStateFactory not set, not creating accessors for class x.y.MyEntity
    The bean DbInitialization is getting managed by the same application context as the SDG setup (config and repositories). I also autowire the graph repository into the bean DbInitialization to make sure that the dependencies should be resolved correctly by the spring context.
    I also use aspectj compile time weaving.

    Here's the complete stack trace:
    Code:
    [2011-08-12 10:31:42.924] ERROR start-signalling-2           org.eclipse.virgo.medic.eventlog.default                         DE0006E Start failed for bundle 'mybundle' version '0.0.1.BUILD-SNAPSHOT'. org.springframework.beans.factory.BeanCreat
    ionException: Error creating bean with name 'dbInitialization': Invocation of init method failed; nested exception is java.lang.NullPointerException
            at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1413)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
            at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
            at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
            at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
            at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
            at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
            at org.eclipse.virgo.kernel.agent.dm.ContextPropagatingTaskExecutor$2.run(ContextPropagatingTaskExecutor.java:95)
            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
            at java.lang.Thread.run(Thread.java:662)
    Caused by: java.lang.NullPointerException: null
            at org.springframework.data.neo4j.support.node.Neo4jNodeBacking.ajc$interMethod$org_springframework_data_neo4j_support_node_Neo4jNodeBacking$org_springframework_data_neo4j_core_NodeBacked$persist(Neo4jNodeBacking.aj:132)
            at x.y.BaseEntity.persist(BaseEntity.java:1)
            at org.springframework.data.neo4j.support.node.Neo4jNodeBacking.ajc$interMethodDispatch1$org_springframework_data_neo4j_support_node_Neo4jNodeBacking$org_springframework_data_neo4j_core_NodeBacked$persist(Neo4jNodeBacking.aj)
            at org.springframework.data.neo4j.repository.NodeGraphRepository.save(NodeGraphRepository.java:42)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:368)
            at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:349)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
            at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
            at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
            at $Proxy157.save(Unknown Source)
            at x.y.MyEntityRepository.save(AbstractBaseRepository.java:135)
            at x.y.MyEntityRepository.save(CollectorRepository.java:1)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
            at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
            at $Proxy158.save(Unknown Source)
            at x.y.DbInitialization.initCollectors(DbInitialization.java:44)
            at x.y.DbInitialization.initDb(DbInitialization.java:34)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:340)
            at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:293)
            at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:130)
            ... 19 common frames omitted
    I'm wondering why this happens in a @PostConstruct method. What am I doing wrong?

    Thanks,
    Marco
    Last edited by marcogerber; Aug 12th, 2011 at 06:23 AM.

  2. #2
    Join Date
    Feb 2012
    Posts
    6

    Default

    Hi Marco,
    I ran into the same issue.
    Did you find any solution for that?

  3. #3
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    As the aspects are also set up with the spring context you might have to declare the dependency in your bean on these beans:

    * neo4jNodeBacking and neo4jRelationshipBacking (the aspects)

    the following dependencies should be resolved automatically, it might be necessary to add them too

    * nodeEntityStateFactory, relationshipEntityStateFactory

Posting Permissions

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