标签: spring-data-neo4j

在Neo4j/Spring-Data中加载/获取Lazy/Eager

我有一个简单的设置,遇到一个令人费解的(至少对我来说)问题:

我有三个相互关联的pojos:

@NodeEntity
public class Unit {
    @GraphId Long nodeId;
    @Indexed int type;
    String description;
}


@NodeEntity
public class User {
    @GraphId Long nodeId;
    @RelatedTo(type="user", direction = Direction.INCOMING)
    @Fetch private Iterable<Worker> worker;
    @Fetch Unit currentUnit;

    String name;

}

@NodeEntity
public class Worker {
    @GraphId Long nodeId;
    @Fetch User user;
    @Fetch Unit unit;
    String description;
}
Run Code Online (Sandbox Code Playgroud)

所以你有User-Worker-Unit有一个"currentunit",它在用户中标记允许直接跳转到"当前单位".每个用户可以有多个工作人员,但只有一个工作人员被分配到一个单元(一个单元可以有多个工作人员).

我想知道的是如何控制"User.worker"上的@Fetch注释.我实际上希望这只在需要的时候加盖,因为大多数时候我只和"工人"一起工作.

我浏览了http://static.springsource.org/spring-data/data-neo4j/docs/2.0.0.RELEASE/reference/html/,对我来说并不是很清楚:

  • worker是可迭代的,因为它应该是只读的(传入关系) - 在文档中这是明确说明的,但是在示例中''Set''在大多数情况下被使用.为什么?或者不重要......
  • 如何让工作人员只加载访问权限?(懒加载)
  • 为什么我需要用@Fetch注释简单的关系(worker.unit).有没有更好的方法?我有另外一个与MANY这样简单关系的实体 - 我真的想避免因为我想要一个对象的属性而加载整个图形.
  • 我错过了一个弹簧配置,所以它适用于延迟加载?
  • 有没有办法通过额外的呼叫加载任何关系(没有标记为@Fetch)?

从我的看法来看,这个构造只要我想要一个Worker就加载整个数据库,即使我大部分时间都不关心用户.

我发现的唯一解决方法是使用存储库并在需要时手动加载实体.

-------更新-------

我已经使用neo4j很长一段时间了,并找到了上述问题的解决方案,不需要一直调用fetch(因此不会加载整个图形).唯一的缺点:它是运行时方面:

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import …
Run Code Online (Sandbox Code Playgroud)

neo4j spring-data-graph spring-data-neo4j

15
推荐指数
1
解决办法
6305
查看次数

org.xml.sax.SAXParseException:src-resolve:无法将名称'repository:auditing-attributes'解析为(n)'属性组'组件

在项目上运行maven测试时出现以下错误.我正在使用Spring Data Neo4j构建测试应用程序.

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.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    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.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 70 in XML document from …
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc neo4j spring-data-neo4j

13
推荐指数
2
解决办法
2万
查看次数

构建基于Neo4j的应用程序 - 使用普通节点和关系坚持使用vanilla API或使用Spring/GORM?

我希望听到任何一个已经构建并实现了大小合适的Neo4j应用程序(10百万个节点/ rels)的人 - 以及你的建议特别是建模和各种API(vanilla java/groovy Neo4j vs Spring-Data) -Neo4j vs Grails GORM/Neo4j).

我感兴趣的是,它是否真的能够为添加额外的OGM(对象图形映射)层和相关的抽象而付出代价?

有没有人的经验是,最好坚持使用节点+属性,关系+属性,遍历和(例如)Cypher来建模和存储数据的"普通"图形建模?

我担心的是,将特定的OGM抽象"强制"到图形数据库中会影响未来调整/更改域模型的灵活性和/或查询数据的灵活性.

我们是Grails商店,我已经尝试过GORM/Neo4J以及spring-data-neo4j.

数据集的主要目的是建模和查询v.large数量的人,他们的别名,他们的同事以及各种犯罪活动和历史之间的关系.将有超过50个主域名类.模型必须具有灵活性(需要在项目的早期阶段快速发展)以及查询的速度和灵活性.

我必须承认,当我可以使用(例如)POJO或POGO,一点Groovy魔术和一些简单的手动域对象< - >节点/关系映射代码时,我很难找到使用OGM层的令人信服的理由.据我所知,我想我会很高兴只处理节点和遍历和Cypher(又名KISS).但我很乐意听取别人的经验和建议.

谢谢你的时间和想法,

TP

grails grails-orm neo4j spring-data-graph spring-data-neo4j

10
推荐指数
1
解决办法
1787
查看次数

无法自动装配.找不到Neo4jTemplate类型的bean

我使用IDEA IntelliJ 12.0.2.

我的application-context.xml是:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
       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">

    <neo4j:config storeDirectory="../embeddedNeo4j"/>

    <context:spring-configured/>

    <context:annotation-config/>
    <context:component-scan base-package="models"/>

</beans>
Run Code Online (Sandbox Code Playgroud)

我的测试类是:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/application-context.xml"})
@Transactional
public class MyTest {

    @Autowired
    Neo4jTemplate template; //=> Could not autowire.No beans of Neo4jTemplate type found

    //my tests here
}
Run Code Online (Sandbox Code Playgroud)

我错过了一些配置吗?

这似乎是Intellij的一个老问题:http://www.markvandenbergh.com/archives/260/autowiring-spring-bean-in-intellij/

java spring intellij-idea spring-data-neo4j

8
推荐指数
1
解决办法
4618
查看次数

Neo4j:Cypher查询属性数组

我有一个域名,其属性名称为"alias",这是一个字符串的arraylist,如下所示:

private List<String> alias;
Run Code Online (Sandbox Code Playgroud)

别名包含以下值:{"John Doe","Alex Smith","Greg Walsh"}

我希望能够像下面这样查询:"我今天看到史密斯"使用下面显示的存储库查询并获取数组值输出"Alex Smith":

@Query("MATCH (p:Person) WHERE {0} IN p.alias RETURN p")    
Iterable<Person> findByAlias(String query);
Run Code Online (Sandbox Code Playgroud)

我尝试了一堆不同的查询,如上所示,但只有在输入查询与数组值完全匹配时才会匹配.

我想做一个输入查询子字符串与数组值匹配.

例如:输入查询:"我今天看到了史密斯"输出:"亚历克斯史密斯"

lucene neo4j spring-data-neo4j spring-data-neo4j-4

8
推荐指数
2
解决办法
7969
查看次数

如何在不杀死VM的情况下关闭并重新打开Spring Data Neo4J上下文

我正在运行一个spring数据neo-4j应用程序(不是基于web的),它在正常操作期间工作正常.

如果我关闭Spring Context'ctx.close()',neo 4J数据库上的锁就会消失.

然后,从应用程序的同一个实例,如果我抓住另一个上下文,我看到锁回来了,但如果我尝试从该上下文中读取/写入该数据库,我会收到一个错误:

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; …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc neo4j spring-data spring-data-neo4j

7
推荐指数
1
解决办法
1609
查看次数

neo4j可以只在内存中运行吗?

是否可以在没有任何持久数据库/文件存储的情况下在内存中运行Neo4j?

来自几个xml/json文件的数据,我们必须使用ConcurrentHashmap将它们加载到jvm堆内存中.由于数据对象具有依赖关系(parent-child,child可以链接回parent),因此我们希望维护一个对象图.在这种情况下有没有办法使用Neo4J; 或者你能建议任何可以支持维护这种对象图的框架.

谢谢.

spring-data-neo4j

7
推荐指数
1
解决办法
4764
查看次数

Neo4j多租户

在neo4j中实现多租户的最佳方式是什么?

我见过Tinkerpop和Spring Data.

我有多个客户端,我想将客户端信息存储在自己的数据库中以确保安全性.

我不想使用标签或索引来解决这个问题.

multi-tenant neo4j spring-data-neo4j tinkerpop

7
推荐指数
2
解决办法
1861
查看次数

如何在Grails 2.4.2项目中集成Spring Data Neo4j和Mongodb

我正在创建一个Grails项目,我需要集成Neo4j和Mongodb,对于neo4j,我使用SDN(Spring Data Neo4j),对于MongoDb,我们使用Grails插件

This is our Dependencies and Plugins 
 dependencies {
            // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
            // runtime 'mysql:mysql-connector-java:5.1.29'
            // runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
        //  compile 'org.grails:grails-datastore-gorm:3.1.2.RELEASE'
        //  compile 'org.grails:grails-datastore-core:3.1.2.RELEASE'
        //  test 'org.grails:grails-datastore-simple:3.1.2.RELEASE'
            //compile 'org.grails:grails-datastore-gorm:3.1.0.RELEASE'
            //compile 'org.grails:grails-datastore-core:3.1.0.RELEASE'
        //  test 'org.grails:grails-datastore-simple:3.1.0.RELEASE'
          //  test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
            compile 'org.springframework.data:spring-data-neo4j-rest:3.2.0.RELEASE'
            compile 'org.springframework.data:spring-data-commons:1.9.0.RELEASE'
            //compile 'javax.validation:validation-api:1.1.0.Final'



        }

        plugins {
            // plugins for the build system only
            build ":tomcat:7.0.54"
            compile ":mongodb:3.0.2"
            // plugins for the compile step

            compile ":scaffolding:2.1.2"
            compile ':cache:1.1.7' …
Run Code Online (Sandbox Code Playgroud)

grails mongodb spring-data-neo4j

7
推荐指数
1
解决办法
332
查看次数

SDN与Neo4j 2.2x

许多人声称SDN版本3.3.1或4.0.0.RC1应该与neo4j 2.2.x一起使用,但我无法使其工作.

我有这个spring配置配置:

<?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>
Run Code Online (Sandbox Code Playgroud)

这会产生以下异常:

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)
Run Code Online (Sandbox Code Playgroud)

查看代码清楚地表明:SDN指的是在2.2.x中消除的neo4j库中的一个类:

org.neo4j.kernel.impl.nioneo.store.StoreId
Run Code Online (Sandbox Code Playgroud)

在这种情况下我有什么选择?

spring-data-neo4j

7
推荐指数
2
解决办法
227
查看次数