Announcement Announcement Module
Collapse
No announcement yet.
Need Some Help w/ Neo4J Setup Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need Some Help w/ Neo4J Setup

    I'm trying to get started understanding the Neo4J capabilities, but running into a configuration issue.

    Here's my Person @NodeEntity:
    Code:
    @NodeEntity(useShortNames = false)
    public class Person
    {
      @GraphId
      private long id;
      private String name;
    
      @RelatedTo(type = "pets", elementClass = Pet.class)
      private Set<Pet> pets;
    
      public long getId()
      {
        return id;
      }
    
      public void setId(long id)
      {
        this.id = id;
      }
    
      public String getName()
      {
        return name;
      }
    
      public void setName(String name)
      {
        this.name = name;
      }
    
      @Override
      public String toString()
      {
        return "User [id=" + id + ", name=" + name + ", pets=" + pets + "]";
      }
    
    }

    And here's my repository code where I'm trying to use the FindFactory for locating a Person node:
    Code:
    @Repository
    public class PersonDao
    {
      @Autowired
      private FinderFactory finderFactory;
    
      private NodeFinder<Person> finder;
    
      @PostConstruct
      public void init()
      {
        finder = finderFactory.createNodeEntityFinder(Person.class);
      }
    
      public List<Person> getAll()
      {
        List<Person> retVal = new LinkedList<Person>();
        
         Iterator<Person> itr = finder.findAll().iterator();
         while (itr.hasNext())
         {
         retVal.add(itr.next());
         }
        return retVal;
      }
    }

    Finally, my Java-based config:
    Code:
    @Configuration
    @Import({Neo4jConfiguration.class, AppFeatures.class})
    public class AppConfig
    {
      @Bean(destroyMethod = "shutdown")
      public EmbeddedGraphDatabase graphDatabaseService()
      {
        EmbeddedGraphDatabase retVal = new EmbeddedGraphDatabase(
            "c:/temp/neoEmbedded");
        return retVal;
      }
    }
    
    @FeatureConfiguration
    class AppFeatures
    {
      @Feature
      public ComponentScanSpec scan()
      {
        return new ComponentScanSpec("org.mycompany.graphexample")
            .excludeFilters(configPackages());
      }
    
      @Feature
      public TxAnnotationDriven txAnnotationDriven()
      {
        TxAnnotationDriven retVal = new TxAnnotationDriven();
        retVal.mode(AdviceMode.ASPECTJ);
        return retVal;
      }
    
      private TypeFilter configPackages()
      {
        return new RegexPatternTypeFilter(Pattern
            .compile("org\\.mycompany\\.graphexample\\.AppConfig"));
      }
    }
    My unit test encounters the following error while trying to load the application context:

    Code:
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDao' defined in file [C:\Documents and Settings\jq240d\Documents\workspace-sts-2.3.2.RELEASE\org.mycompany.graphexample\bin\org\mycompany\graphexample\PersonDao.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.mycompany.graphexample.PersonDao]: Constructor threw exception; nested exception is java.lang.Error: Unresolved compilation problems: 
    	Bound mismatch: The type Person is not a valid substitute for the bounded parameter <T extends GraphBacked<Node>> of the type NodeFinder<T>
    	Bound mismatch: The generic method createNodeEntityFinder(Class<T>) of type FinderFactory is not applicable for the arguments (Class<Person>). The inferred type Person is not a valid substitute for the bounded parameter <T extends NodeBacked>
    
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965)
    	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:295)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:900)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:455)
    	at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:68)
    	at org.mycompany.graphexample.AnnotationConfigContextLoader.loadContext(AnnotationConfigContextLoader.java:17)
    	at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280)
    	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304)
    	... 24 more
    Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.mycompany.graphexample.PersonDao]: Constructor threw exception; nested exception is java.lang.Error: Unresolved compilation problems: 
    	Bound mismatch: The type Person is not a valid substitute for the bounded parameter <T extends GraphBacked<Node>> of the type NodeFinder<T>
    	Bound mismatch: The generic method createNodeEntityFinder(Class<T>) of type FinderFactory is not applicable for the arguments (Class<Person>). The inferred type Person is not a valid substitute for the bounded parameter <T extends NodeBacked>
    
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162)
    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958)
    	... 38 more
    Caused by: java.lang.Error: Unresolved compilation problems: 
    	Bound mismatch: The type Person is not a valid substitute for the bounded parameter <T extends GraphBacked<Node>> of the type NodeFinder<T>
    	Bound mismatch: The generic method createNodeEntityFinder(Class<T>) of type FinderFactory is not applicable for the arguments (Class<Person>). The inferred type Person is not a valid substitute for the bounded parameter <T extends NodeBacked>
    
    	at org.mycompany.graphexample.PersonDao.<init>(PersonDao.java:20)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
    	... 40 more

  • #2
    It looks as if the aspects have not been applied to your domain class(es).
    Can you also show your build-config that includes the aspectj-compiler(plugin) with the dependencies to aspect-libraries of spring-aspects and spring-data-neo4j?

    Otherwise I haven't used a _complete_ Java config so far, will try to add that to the test cases to see if there are any issues with that.

    Some other minor notes:
    * normally you don't need the graph - id (and you can't set it anyway!)
    * useShortNames=false makes the resulting graph less readable in any visualization, so you only need that if you want this additional type information in all properties
    * the result of finder.findAll() might be a list, so you could check that and then return the list directly

    Cheers

    Michael

    Comment


    • #3
      We're not using Maven where I am. What's the easiest way of getting the aspects applied at build-time without using Maven?

      Comment


      • #4
        What build-tool are you using?

        general reference of ajc:
        http://www.eclipse.org/aspectj/doc/r...e/ajc-ref.html
        (You can search for examples there.)

        Comment


        • #5
          There are a couple of options if you aren't using maven:

          1) Just use the command line compiler ajc, like you use javac. The compiler is included in the standard distribution from: http://eclipse.org/aspectj/downloads.php

          Typically it is invoked like this:

          ajc -d output Foo.java Bar.java -aspectpath myaspectlibrary.jar
          And that will produce the compiled code in the output folder, woven with aspects from myaspectlibrary.jar.

          2) Use the Ant task integration. If you have been using the javac task from Ant, it can be as simple as changing that to 'iajc'. The options are quite similar to javac but we also support extra options for passing in aspect libraries. See here for Ant doc: http://www.eclipse.org/aspectj/doc/r...asks-iajc.html

          cheers
          Andy
          ---
          Andy Clement
          AspectJ Project Lead

          Comment


          • #6
            Thanks for this advice. I'll give the Ant task a try.

            Regarding the Spring Data Graph documentation, I'd recommend also including this info in the documentation. I'm sure there are others out there like me who still use Ant for building and Ivy (or something similar) for dependency management.

            Comment

            Working...
            X