EzDevInfo.com

spring-data-neo4j

Provides support to increase developer productivity in Java when using the neo4j graph database. Uses familiar Spring concepts such as a template classes for core API usage and provides an annotation based programming model using AspectJ Spring Data Neo4j

How to use Neo4J via Spring Roo 1.2.x?

How to use Neo4J via Spring Roo 1.2.x?

Books & online documentation seem to suggest that Neo4j is a search addon with Spring Roo 1.2.4. Although I can manually add the spring-data-neo4j dependency, I would really like to leverage the Roo capabilities.

Spring Roo  1.2.4.RELEASE [rev 75337cf]

roo> addon search graph

0 found, sorted by rank; T = trusted developer; R = Roo 1.2 compatible
ID T R DESCRIPTION -------------------------------------------------------------
[HINT] use 'addon info id --searchResultId ..' to see details about a search result
[HINT] use 'addon install id --searchResultId ..' to install a specific search result, or
[HINT] use 'addon install bundle --bundleSymbolicName TAB' to install a specific add-on version

Source: (StackOverflow)

Correct way to get transactions using Spring Data Neo4j's simple object/graph mapping?

I'm using the simple object/graph mapping in Spring Data Neo4j 2.0, where I perform persistence operations using the Spring Data repository framework. I'm working with the repositories rather than working with the Neo4jTemplate. I inject the repositories into my Spring Web MVC controllers, and the controllers call the repos directly. (No intermediate service layer--my operations are generally CRUDs and finder queries.)

When I do read operations, there are no issues. But when I do write operations, I get "NotInTransactionException". My understanding is that read ops in Neo4j don't require transactions, but write ops do.

What's the best way to get transactions into the picture here, assuming I want to stick with the simple OGM? I'm wanting to use @Transactional, but putting that on the various repository interfaces doesn't work. If I introduce an intermediate service tier in between the controllers and the repositories and then annotate the service beans with @Transactional, then it works, but I'm wondering whether there's a simpler way to do it. Without Spring Data, I'd typically have access to the DAO (repository) implementations, so I'd be able to annotate the concrete DAOs with @Transactional if I wanted to avoid a pass-through service tier. With Spring Data the repos are dynamically generated so that doesn't appear to be an option.


Source: (StackOverflow)

Advertisements

Spring Data Neo4j in Play 2.x app using Scala

I am currently working on a web service backed by Neo4j (v2.1.2, hosted on GrapheneDB) and Play (v2.3) using Scala (2.11.1) (hosted on Heroku).

Until now AnormCypher connects the Play app with the Neo4J instance and all things are working as expected.

However using AnormCypher doesn't feel quite right. I have to write a lot boiler plate code to convert the results I get from AnormCypher to the Scala classes which are used for the business logic. I would prefer using something similar to Spring Data Neo4j.

The code in the examples looks very clean to me and I want to try it in project.

All these technologies are new to me so I need some help:

  • How can I use Spring Data Neo4j in the play app (build.sbt, plugin.sbt, ...)?
  • Which difficulties do I have to expect regarding the fact that I am not using the whole Spring stack?
  • Which drawbacks does it have to integrate a Java based framework in a Scala app ?

Source: (StackOverflow)

Error loading recursive relationship by loadAll by ids

Using the new Neo4j 2.3 OGM. When trying to load entities by id I have the following problem:

@NodeEntity
class Person {
    Long id;
    String name;

    @Relationship(type="Friend", direction = Direction.OUTGOING)
    public List<Person> friends;
}

assuming (1, "Alex") is friends with (2, "Joseph") and (3, "Guy"). (4, "Nati") is friends with (5, "Amit"), using the following code:

session.loadAll(Person.class, Arrays.toList(new Long() { 1L, 4L }), 1)

should return 2 Person objects, Alex containing two friends (Guy, Joseph) and Nati containing one friend yet what it actually returns is 5 objects (Alex, Guy, Joseph, Nati, Amit). Although Mike and Nati do contain their friends within, it seems weird (and certainly unwanted) that I requested Persons by two ids and got an Iterable containing 5. Does anyone know why this is? is this a bug?


Source: (StackOverflow)

Spring data neo4j 3.3.1 and Neo4j 2.2.3 transaction builder error

I am currently using Spring Data Neo4j 3.3.0 with Play 2.3.8 using the tuxburner plugin and working remotely with a neo4j 2.1.7 DB.

I saw that the new spring data version supports neo4j 2.2 and i wanted to upgrade to it. I changed my dependencies to the new versions and am getting the following error:

BeanCreationException: Error creating bean with name 'restNeo4jConfig': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.data.neo4j.config.Neo4jConfiguration.setGraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService);
nested exception is java.lang.NoClassDefFoundError: org/neo4j/kernel/TransactionBuilder

It seems to be an old issue that should be resolved in 3.3.1 since neo4j 2.2 changed a lot of their internal API and this class no longer exists.

Maybe the way I work with Spring Data is no longer right and needs to be changed.

I've created an example play app that shows the problem: https://github.com/OlympusTeam/Olympus


Source: (StackOverflow)

Migration to Spring Data Neo4J 3.3 caused neo to return old data

I'm running Spring Data Neo4j on two playframework 2.3.8 servers, after migrating to the new spring data neo4j (3.3.0) have been getting different results from queries from each of the servers. This didn't happen before when i was using version 3.2.1. I am using neo4j as a server and not embedded.

My site shows a status (NORMAL or ERROR) which is changed by users. The status is updated every 2 seconds by polling one of the two servers. The problem is I have times that each server returns different results. So although the status is stable in the DB (confirmed by the neo4j console) it changes rapidly for the users every time they poll a different server.

I thought that perhaps i am getting a cached result from the server but couldn't find anything about caching in the new spring data that would explain this.

I've noticed that this problem happens when I use the repository findOne function and when i switched to using a new function with a query (@query("match n where id(n) = {0} return n")) it stopped happening. It happens in a few other places including when i use template.fetch(o). it may happen also in other places that i'm not aware of.


Source: (StackOverflow)

Neo4j 1.9.9 legacy index very slow after deletes

Using Neo4j 1.9.9. Some Cypher queries we were running seemed to be unreasonably slow. Some investigation showed that:

  • Delete 200k nodes takes about 2-3 seconds on my hardware (MacBook Pro), when I select them using:

    START n=node(*) DELETE n
    
  • Adding a WHERE clause does not significantly slow it down

  • If the nodes were selected using an index, it has similar performance, e.g.

    START n=node:__types__(className="com.e2sd.domain.Comment") DELETE n
    
  • Except that when repeating the previous test, it is 20x or more slower, with actual time varying from 80 to several hundred seconds. Even more curious, it doesn't matter whether I repeat the test in the same JVM or start a new program, or clear out all the nodes in the database and verify it has zero nodes. The index-based delete is extremely slow on any subsequent run of the test until I clobber my neo4j data directory with

     rm -R target/neo4j-test/
    

I'll give some example Scala code here. I'm happy to provide more detail as required.

for (j <- 1 to 3) {
  log("Total nodes in database: " + inNeo4j( """ START n=node(*) RETURN COUNT(n) """).to(classOf[Int]).single)
  log("Start")
  inNeo4j(""" CREATE (x) WITH x FOREACH(i IN RANGE(1, 200000, 1) : CREATE ({__type__: "com.e2sd.domain.Comment"})) """)
  rebuildTypesIndex()
  log("Created lots of nodes")
  val x = inNeo4j(
    """
    START n=node:__types__(className="com.e2sd.domain.Comment")
    DELETE n
    RETURN COUNT(n)
    """).to(classOf[Int]).single
  log("Deleted x nodes: " + x)
}

// log is a convenience method that prints a string and the time since the last log
// inNeo4j is a convenience method to run a Cypher query



def rebuildTypesIndex(): Unit = {
  TransactionUtils.withTransaction(neo4jTemplate) {
    log.info("Rebuilding __types__ index...")
    val index = neo4jTemplate.getGraphDatabase.getIndex[Node]("__types__")
    for (node <- GlobalGraphOperations.at(neo4jTemplate.getGraphDatabaseService).getAllNodes.asScala) {
      index.remove(node)
      if (node.hasProperty("__type__")) {
        val typeProperty = node.getProperty("__type__")
        index.add(node, "className", typeProperty)
      }
    }
    log.info("Done")
  }
}

We are using Neo4j embedded here with the following Spring Data configuration.

<bean id="graphDbFactory" class="org.neo4j.graphdb.factory.GraphDatabaseFactory"/>
<bean id="graphDatabaseService" scope="singleton" destroy-method="shutdown"
  factory-bean="graphDbFactory" factory-method="newEmbeddedDatabase">
  <constructor-arg value="target/neo4j-test"/>
</bean>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="my.package.*"/>

Why is the DELETE query slow under the conditions described?


Source: (StackOverflow)

Neo4j's advanced mapping mode performance

I've used both Neo4j's simple and advanced mapping modes in my Spring Data Neo4j project. Since I've switched from simple to advanced mappings, the project's performance is a lot, and I mean really a lot better than before. I've got no exact numbers to present, but it is for sure a multitude. Can somebody clarify why advanced mapping mode outperforms simple mapping?

I've read the Prorgramming Model page from the SDN documentation, but I couldn't find the exact reason.

For the record, I'm using the @Transactional support from Spring.


Source: (StackOverflow)

SDN 3.3.0 or SDN 4.0M1?

Currently starting a new Java project with Neo4j (2.2 probably) external server as primary database, we decided to use SDN. This is going to be a year-long project with multiple intermediate releases. We wonder about whether we should go for the current release (3.3.0) or the very new 4.0.0.M1 version.

Considering this GraphAware article, previous StackOverflow answer (by Michal Bachman and Michael Hunger) and keeping in mind the SDN 4.0.0.M1 migration chapter :

  • What would be the best choice today ?

Personal consideration : I would definitely go for the 4.0.0M1 considering the improvements done, but then the question evolutes to :

  • When (approximately of course) will/should/may the "ready for production" version of SDN4 be released ? The answer 1 month earlier was around May, any update about that ?

Thank you


Source: (StackOverflow)

Neo4j - Unable to create Relationship entities

I am trying to insert the relationships between two nodes in Neo4j. I am using the Neo4J(2.1.8 Community) & spring-data-neo4j(3.3.0.RELEASE).

I am using trying to create the Employee-Manager relationship. This relationship entity is Report. (Both class are given below)

But when I am trying to save the relation ship

Employee manager = new Employee("Dev_manager", "Management");
Employee developer = new Employee("Developer", "Development");
developer.setReportsTo(manager);
developer.relatedTo(manager, "REPORTS_TO")
employeeRepository.save(developer);

I am getting exception as

Exception in thread "main" org.springframework.dao.DataRetrievalFailureException: RELATIONSHIP[0] has no property with propertyKey="type".; nested exception is org.neo4j.graphdb.NotFoundException: RELATIONSHIP[0] has no property with propertyKey="type".

Can any one please help me that what is exactly wrong in this code.

The same code works after I change the type of relations in Employee as

@RelatedToVia(type = "REPORT_TO", elementClass = Report.class, direction = Direction.INCOMING)

Note: I am using this reference for this tutorial.

Employee.java class

@NodeEntity
public class Employee {

@GraphId
private Long id;
private String name;
private String department;

@Fetch
@RelatedTo(type = "REPORTS_TO")
private Employee reportsTo; //Employee reports to some employee (i.e. Manager).

@Fetch
@RelatedTo(type = "REPORTS_TO", direction = Direction.INCOMING)
Set<Employee> directReport; //All the employees who reports to this particular this employee.

@Fetch
@RelatedToVia(type = "REPORTS_TO", elementClass = Report.class, direction = Direction.INCOMING)
Set<Report> relations = new HashSet<Report>(); // All the incoming relationship entities.
//*** Constructor, Getter-setters and other methods...
}

Report.java class

@RelationshipEntity(type = "REPORTS_TO")
public class Report {

@GraphId
private Long id;
private String title;

@Fetch
@StartNode
private Employee child;

@Fetch
@EndNode
private Employee parent;
//*** Constructor, Getter-setters and other methods...
}

**Update: ** I have created 2 relations using this class structure. And I got the below result. enter image description here

It looks like it creates 2 relations between the node. 1 is empty relation using reportsTo(i.e. REPORTS_TO) and another relation using the relations(i.e. REPORT_TO). Can anyone please update why this is happening?


Source: (StackOverflow)

Neo4J Spring Data - Error adding element with @RelatedToVia relationship to index __rel_types__ using SpringCypherRestGraphDatabase

I'm working on Neo4j Spring Data project and have started using a "RelationshipEntity" and the "@RelatedToVia" relationship to better model some relationships.

The problem I'm having is if I run an embedded database everything is fine but when I run with a SpringCypherRestGraphDatabase I keep getting the error "Error adding element... to index __rel_types__":

Any pointers would be great!!

Stacktrace:

Caused by: java.lang.RuntimeException: Error adding element 52 className AlsoKnownAs to index __rel_types__
at org.neo4j.rest.graphdb.RestAPIImpl.addToIndex(RestAPIImpl.java:703)
at org.neo4j.rest.graphdb.RestAPICypherImpl.addToIndex(RestAPICypherImpl.java:683)
at org.neo4j.rest.graphdb.index.RestIndex.add(RestIndex.java:58)
at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexBasedTypeRepresentationStrategy.add(AbstractIndexBasedTypeRepresentationStrategy.java:139)
at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexBasedTypeRepresentationStrategy.addToTypesIndex(AbstractIndexBasedTypeRepresentationStrategy.java:131)
at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexBasedTypeRepresentationStrategy.writeTypeTo(AbstractIndexBasedTypeRepresentationStrategy.java:74)
at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.writeTypeTo(TRSTypeAliasAccessor.java:46)
at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.writeTypeTo(TRSTypeAliasAccessor.java:26)
at org.springframework.data.convert.DefaultTypeMapper.writeType(DefaultTypeMapper.java:199)
at org.springframework.data.convert.DefaultTypeMapper.writeType(DefaultTypeMapper.java:186)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.write(Neo4jEntityConverterImpl.java:168)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedConverter.write(Neo4jEntityPersister.java:179)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist(Neo4jEntityPersister.java:254)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist(Neo4jEntityPersister.java:235)
at org.springframework.data.neo4j.support.Neo4jTemplate.save(Neo4jTemplate.java:365)
at org.springframework.data.neo4j.fieldaccess.RelatedToViaCollectionFieldAccessorFactory$RelatedToViaCollectionFieldAccessor.persistEntities(RelatedToViaCollectionFieldAccessorFactory.java:99)
at org.springframework.data.neo4j.fieldaccess.RelatedToViaCollectionFieldAccessorFactory$RelatedToViaCollectionFieldAccessor.setValue(RelatedToViaCollectionFieldAccessorFactory.java:93)
at org.springframework.data.neo4j.fieldaccess.ManagedFieldAccessorSet.updateValue(ManagedFieldAccessorSet.java:112)
at org.springframework.data.neo4j.fieldaccess.ManagedFieldAccessorSet.update(ManagedFieldAccessorSet.java:100)
at org.springframework.data.neo4j.fieldaccess.ManagedFieldAccessorSet.add(ManagedFieldAccessorSet.java:126)

RelationshipEntity

import org.springframework.data.neo4j.annotation.EndNode;
import org.springframework.data.neo4j.annotation.Fetch;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.RelationshipEntity;
import org.springframework.data.neo4j.annotation.StartNode;

@RelationshipEntity(type = "AKA")
public class AlsoKnownAs {
@GraphId Long id;
String name;

@Fetch @StartNode private Person identity;
@Fetch @EndNode private Person pseudenom; 


public AlsoKnownAs setNickname(String nickName){
    this.name = nickName;

    return this;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public Person getIdentity() {
    return identity;
}

public void setIdentity(Person identity) {
    this.identity = identity;
}

public Person getPseudenom() {
    return pseudenom;
}

public void setPseudenom(Person pseudenom) {
    this.pseudenom = pseudenom;
}

}

Node Entity

import java.util.HashSet;
import java.util.Set;

import org.neo4j.graphdb.Direction;
import org.springframework.data.neo4j.annotation.Fetch;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.annotation.RelatedTo;
import org.springframework.data.neo4j.annotation.RelatedToVia;

@NodeEntity
public class Person {

@GraphId Long id;
public String name;

public Person() {}
public Person(String name) { this.name = name; }

@RelatedTo(type="TEAMMATE", direction=Direction.BOTH)
public @Fetch Set<Person> teammates;

@RelatedToVia(type="AKA") 
Set<AlsoKnownAs> identities;


public void worksWith(Person person) {
    if (teammates == null) {
        teammates = new HashSet<Person>();
    }
    teammates.add(person);
}

public String toString() {
    String results = name + "'s teammates include\n";
    if (teammates != null) {
        for (Person person : teammates) {
            results += "\t- " + person.name + "\n";
        }
    }
    return results;
}


public void identify(Person person,  String nickName) { 
    AlsoKnownAs aka = new AlsoKnownAs();
    aka.setIdentity(this);
    aka.setPseudenom(person);
    aka.setName(nickName);

    this.identities.add(aka);

  }

}

POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.teralitic</groupId>
<artifactId>geonames</artifactId>
<version>0.0.1-SNAPSHOT</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.3.RELEASE</version>
</parent>

<properties>
    <spring-data-releasetrain.version>Fowler-RELEASE</spring-data-releasetrain.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>3.3.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j-rest</artifactId>
        <version>3.3.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>javax.el</groupId>
        <artifactId>javax.el-api</artifactId>
        <version>2.2.4</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <jvmArguments>
                    -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
                </jvmArguments>
            </configuration>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-releases</id>
        <name>Spring Releases</name>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
    <repository>
        <id>neo4j</id>
        <name>Neo4j</name>
        <url>http://m2.neo4j.org/</url>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-releases</id>
        <name>Spring Releases</name>
        <url>https://repo.spring.io/libs-release</url>
    </pluginRepository>
</pluginRepositories>

Edited I can see the same issue was happening on an old Spring Data build: https://build.spring.io/browse/SPRINGDATA-NIGHTLY-JOB1-697/test/case/92176623;jsessionid=5EE45702C67548804FEF985C00F5DAD2

Still investigating what might have caused that.


Source: (StackOverflow)

SDN with Neo4j 2.2x

Many are claiming that the SDN version 3.3.1 or 4.0.0.RC1 should work with neo4j 2.2.x but I could not make it to work.

I have this spring config configuration:

<?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.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <context:annotation-config />
    <context:spring-configured />

    <neo4j:config graphDatabaseService="graphDatabaseService" base-package="com.x.protogy.neo4j"/>
    <bean id="graphDatabaseService"
        class="org.springframework.data.neo4j.rest.SpringCypherRestGraphDatabase">
      <constructor-arg index="0" value="http://localhost:7476/db/data" />
    </bean>
    <tx:annotation-driven mode="aspectj"
        transaction-manager="transactionManager" />

</beans>

That generates this exception:

Caused by: java.lang.ClassNotFoundException: org.neo4j.kernel.impl.nioneo.store.StoreId
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1324)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1177)

Looking in the code makes it clear: SDN refers to a class in neo4j library that was eliminated in 2.2.x:

org.neo4j.kernel.impl.nioneo.store.StoreId

What are my options in this case?


Source: (StackOverflow)

Can't move to Neo4j 2.2.0 and Spring Data Neo4j 3.3.0.RELEASE

I use Spring 4.1.6.RELEASE and Spring Boot 1.2.3.RELEASE. Right now, I can't smoothly move from Neo4j 2.1.7 and SDN 3.2.2.RELEASE to Neo4j 2.2.0 and SDN 3.3.0.RELEASE

First of all, Neo4jHelper class is absent... so what should be used instead ?

Also, my tests crashes with a following exceptions:

org.springframework.dao.InvalidDataAccessApiUsageException: nested exception is org.neo4j.graphdb.NotInTransactionException
    at org.springframework.data.neo4j.support.Neo4jExceptionTranslator.translateExceptionIfPossible(Neo4jExceptionTranslator.java:51)
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)

but on the previous versions everything work fine(My DAO and Services are annotated with @Transactional).

How to configure appropriate TX manager for Neo4j in my Spring Boot application ?

Right now NullTransactionManager are used and I think this is a reason of the issue:

2015-04-03 11:40:36 [main] INFO  o.s.c.a.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@12db5286: startup date [Fri Apr 03 11:40:36 EEST 2015]; root of context hierarchy
2015-04-03 11:40:37 [main] INFO  o.s.b.f.a.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2015-04-03 11:40:38 [main] INFO  o.s.t.jta.JtaTransactionManager - Using JTA UserTransaction: org.springframework.transaction.jta.UserTransactionAdapter@5909b7c2
2015-04-03 11:40:38 [main] INFO  o.s.t.jta.JtaTransactionManager - Using JTA TransactionManager: org.springframework.data.neo4j.config.NullTransactionManager@16bc4d92

what I'm doing wrong ?


Source: (StackOverflow)

Issue wiring together spring-data-neo4j standalone spring project

I'm trying to create a sandbox using spring to handle dependency injection. My sandbox is several domain classes, as well as a MainClass, which has a main(String[] args) method in it.

In annotating my TestClass with @Component and it just contains

@Autowired
private Neo4jTemplate neo4jTemplate;

in it.

In my main method, I call ClassPathXmlApplicationContext on my applicationContext.xml file, which is made up of:

<context:annotation-config/>
<context:spring-configured/>
<context:component-scan base-package="org.neuralsandbox"/>

<neo4j:config storeDirectory="data/sandbox.db"/>

but my program fails to execute at the line here I declare my ClassPathXmlApplicationContext, with a massive stack trace, I'll print the first and last throwables.

First:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testClass': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.data.neo4j.support.Neo4jTemplate org.neuralsandbox.TestClass.neo4jTemplate; 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$$a3874640.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$$a3874640.mappingInfrastructure() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jTransactionManager' 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.transaction.PlatformTransactionManager org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$a3874640.neo4jTransactionManager()] threw exception; nested exception is java.lang.NoSuchMethodError: org.neo4j.kernel.impl.transaction.UserTransactionImpl.<init>(Lorg/neo4j/graphdb/GraphDatabaseService;)V
    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)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at org.neuralsandbox.MainClass.main(MainClass.java:8)

Last:

Caused by: java.lang.NoSuchMethodError: org.neo4j.kernel.impl.transaction.UserTransactionImpl.<init>(Lorg/neo4j/graphdb/GraphDatabaseService;)V
    at org.springframework.data.neo4j.config.Neo4jConfiguration.createJtaTransactionManager(Neo4jConfiguration.java:240)
    at org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTransactionManager(Neo4jConfiguration.java:232)
    at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$a3874640.CGLIB$neo4jTransactionManager$21(<generated>)
    at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$a3874640$$FastClassByCGLIB$$ed4fda1e.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:210)
    at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$a3874640.neo4jTransactionManager(<generated>)
    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.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:145)
    ... 72 more

I'm using neo4j 1.7 and spring-data-neo4j 2.0.0.RELEASE, as well as spring 3.1.0.RELEASE.

I haven't found a good reason, using the tutorials provided at spring-data-neo4j, for why it would be throwing this exception. Can anyone help?


Source: (StackOverflow)

How to close and re-open Spring Data Neo4J contexts without killing the VM

I'm running a spring data neo-4j application (not web based) which works fine during normal operation.

If I close the Spring Context 'ctx.close()' the lock on the neo 4J database goes away.

Then, from the same instance of the application, if I grab another Context I see the lock come back, but if I try and read / write from that database from that context I get an error:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.data.neo4j.config.Neo4jConfiguration#0': Unsatisfied dependency expressed through bean property 'conversionService': : 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.MappingInfrastructureFactoryBean org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$64cefd6f.mappingInfrastructure() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'typeRepresentationStrategyFactory' 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.typerepresentation.TypeRepresentationStrategyFactory org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$64cefd6f.typeRepresentationStrategyFactory() throws java.lang.Exception] threw exception; 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.IllegalStateException: Unable to lock store [C:\app_data\gelato\data\neostore], this is usually a result of some other Neo4j kernel running using the same store.; 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.MappingInfrastructureFactoryBean org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$64cefd6f.mappingInfrastructure() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'typeRepresentationStrategyFactory' 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.typerepresentation.TypeRepresentationStrategyFactory org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$64cefd6f.typeRepresentationStrategyFactory() throws java.lang.Exception] threw exception; 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.IllegalStateException: Unable to lock store [C:\app_data\gelato\data\neostore], this is usually a result of some other Neo4j kernel running using the same store.

Is there a way to successfully close and then re-open the Application Context within a single instance of an application (ie without shutting down the virtual machine) ?

I was initially calling shutdown() on the graph database, but changed this as Michael Hunger told me not to do it.

our problem can be reproduced in our domain like this.

AbstractApplicationContext ctx = new FileSystemXmlApplicationContext("neo4jconfig.xml");
OurDomainService domainService = (OurDomainService) ctx.getBean(OurDomainServiceImpl.class);
// This works
domainService.save(data);
// this releases the lock
ctx.close();
// this re-creates the lock and the context looks actvive
ctx = new FileSystemXmlApplicationContext("neo4jconfig.xml");
domainService = (OurDomainService) ctx.getBean(OurDomainServiceImpl.class);
// this errors out
domainService.save(data);

Here's the XML file we use to create the context.

<?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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/neo4j
http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">

<context:spring-configured/>
    <context:annotation-config/>
    <context:component-scan base-package="OurData" />

    <neo4j:config storeDirectory="c:/app_data/data"/>
    <neo4j:repositories base-package="OurData"/>

</beans>

Source: (StackOverflow)