Announcement Announcement Module
Collapse
No announcement yet.
Spring Data Neo4j: Using SubReference-TypeRepresentationStrategy Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data Neo4j: Using SubReference-TypeRepresentationStrategy

    Hello all

    I started this question on stackoverflow (http://stackoverflow.com/questions/1...tegy-for-neo4j) and was asked to post it with code somewhere else.

    Basically I want to use the entity type representation with subreference node, as it is mentioned in the Good Relationships book. I tried with Michael Hungers solution but it didn't work. I don't have much experience with Spring as a whole, so I may be missing something in the configuration.

    I am using Spring Data Neo4j 2.0.1.RELEASE. Configuration is as follows:

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    
    	<context:annotation-config />
    	<context:component-scan base-package="myproject"></context:component-scan>
    	<context:spring-configured />
    	<tx:annotation-driven mode="proxy" />
    
    	<neo4j:config graphDatabaseService="graphDatabaseService" />
    	<neo4j:repositories base-package="myproject.db.repositories" />
    	
    	
    	<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase"
    		destroy-method="shutdown" scope="singleton">
    		<constructor-arg value="target/neo4j-db" />
    	</bean>
    
    	<bean id="delegatingGraphDatabase"
    		class="org.springframework.data.neo4j.support.DelegatingGraphDatabase">
    		<constructor-arg index="0" ref="graphDatabaseService" />
    	</bean>
    
    	<bean id="typeRepresentationStrategyFactory" class="org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory">
    		<constructor-arg index="0" ref="delegatingGraphDatabase" />
    		<constructor-arg index="1" value="SubRef" />
    	</bean>
    </beans>
    Without the '<constructor-arg index="1" value="SubRef" />' it works. With it the following exception is thrown at me:
    Code:
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hyperlinkRepository': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.data.neo4j.support.Neo4jTemplate condor.db.repositories.impl.HyperlinkRepository.template; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jTemplate' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public final org.springframework.data.neo4j.support.Neo4jTemplate org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$e80c966e.neo4jTemplate() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingInfrastructure' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public final org.springframework.data.neo4j.support.MappingInfrastructure org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$e80c966e.mappingInfrastructure() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'typeRepresentationStrategyFactory' defined in class path resource [condorDbContext.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1073)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)

  • #2
    I finally got it to work. With a little coaching in Spring I started to understand the configuration a bit better. I still don't know, why the suggested solution from Michael Hunger would work in his tests, but not for my project. However, since it works for me now, I don't care too much.

    For all who may be interested, I had to extend the configuration to create the TypeRepresentationStrategyFactory a bit:

    Code:
    <bean id="subref" factory-method="valueOf"
    	class="org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory.Strategy">
    	<constructor-arg>
    		<value>SubRef</value>
    	</constructor-arg>
    </bean>
    
    <bean id="typeRepresentationStrategyFactory"	
    	class="org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory">
    	<constructor-arg index="0" ref="delegatingGraphDatabase" />
    	<constructor-arg index="1" ref="subref" />
    </bean>
    For a bit more information you can read the edited section of my StackOverflow question (http://stackoverflow.com/questions/1...tegy-for-neo4j).

    Thanks

    Comment


    • #3
      HI there. I've been struggling with this for days. Why does it only work with a DelegatingGraphDatabase and not with the actual EmbeddedGraphDatabase? So frustrating that there is no documentation on setting this up. Would also like to know what the DelegatingGraphDatabase does in all this. If you know of any documentation - please post. Thanks. Here is my final working config:

      Code:
              <bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase" destroy-method="shutdown">
                  <constructor-arg index="0" value="target/testdb"/>
              </bean>
      
              <bean id="delegatingGraphDatabase" class="org.springframework.data.neo4j.support.DelegatingGraphDatabase">
                  <constructor-arg index="0" ref="graphDatabaseService" />
              </bean>
      
              <bean id="subref" factory-method="valueOf"
                    class="org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory.Strategy">
                  <constructor-arg>
                      <value>SubRef</value>
                  </constructor-arg>
              </bean>
      
              <bean id="typeRepresentationStrategyFactory"
                    class="org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory">
                  <constructor-arg index="0" ref="delegatingGraphDatabase" />
                  <constructor-arg index="1" ref="subref" />
              </bean>

      Comment

      Working...
      X