我想在我的neo4j数据库中存储一些数据.我使用spring-data-neo4j.
我的代码如下:
for (int i = 0; i < newRisks.size(); i++) {
myRepository.save(newRisks.get(i));
System.out.println("saved " + newRisks.get(i).name);
}
Run Code Online (Sandbox Code Playgroud)
我的newRisks-array包含大约60000个对象和60000个边.每个节点和边都有一个属性.这个循环的持续时间大约是15到20分钟,这是正常的吗?我使用Java VisualVM来搜索一些瓶颈,但我的平均CPU使用率为10 - 25%(4个核心),而我的堆不到一半.
有什么选择可以提升这个操作吗?
编辑:额外的是,在第myRepository.save(newRisks.get(i));一次输出即将到来之前的几分钟,jvm 第一次调用下降的fpr
第二次编辑:
类风险:
@NodeEntity
public class Risk {
//...
@Indexed
public String name;
@RelatedTo(type = "CHILD", direction = Direction.OUTGOING)
Set<Risk> risk = new HashSet<Risk>();
public void addChild(Risk child) {
risk.add(child);
}
//...
}
Run Code Online (Sandbox Code Playgroud)
创造风险:
@Autowired
private Repository myRepository;
@Transactional
public Collection<Risk> makeSomeRisks() {
ArrayList<Risk> newRisks = new ArrayList<Risk>();
newRisks.add(new Risk("Root"));
for (int i …Run Code Online (Sandbox Code Playgroud) 我刚刚了解到,当我在 neo4j 中创建两个节点之间的关系时,它们都被锁定(http://docs.neo4j.org/chunked/stable/transactions-locking.html)。然而,在我们的项目中,我们有可以实例化的元素,并且最终在图中有两个通过“INSTANCE_OF”关系链接的节点。例如,如果我实例化元素 B,我就会有一个新元素 B1。它们存储在图中,如 B<-INSTANCE_OF-B1。我的问题是许多用户可以同时实例化元素 B,这会导致死锁。请问我怎样才能避免这些僵局?我不需要在 B 上写入属性,我只想将 B1 “附加”到我的图中的 B 。在 B1 中拥有代表 B id 的属性是否会比将它们与关系链接起来是更好的解决方案?我认为不会,因为我们失去了所有的图形兴趣,但我真的不知道如何避免这些僵局?
非常感谢您的帮助
我在两个playframework 2.3.8服务器上运行Spring Data Neo4j ,迁移到新的spring数据后neo4j(3.3.0)从每个服务器的查询得到不同的结果.这在我使用3.2.1版之前没有发生过.我使用neo4j作为服务器而不是嵌入式.
我的站点显示用户更改的状态(NORMAL或ERROR).通过轮询两个服务器之一,每2秒更新一次状态.问题是我有时间每个服务器返回不同的结果.因此,尽管数据库中的状态是稳定的(由neo4j控制台确认),但每次轮询不同服务器时,用户都会快速更改.
我想也许我从服务器获得缓存结果但是在新的弹簧数据中找不到任何关于缓存的信息可以解释这一点.
我注意到这个问题发生在我使用存储库findOne函数时,当我切换到使用带有查询的新函数时(@query("match n where id(n) = {0} return n"))它停止发生.它发生在其他一些地方,包括我使用的时候template.fetch(o).它也可能发生在我不知道的其他地方.
neo4j playframework spring-data spring-data-neo4j playframework-2.3
我需要创建一个A类的新节点,它与User节点有关系:
@NodeEntity
public class A implements Serializable {
/**
* Graph node identifier
*/
@GraphId
private Long nodeId;
/**
* Enity identifier
*/
private String id;
//... more properties ...
@Relationship(type = "HAS_ADVERTISER", direction = Relationship.OUTGOING)
private User user;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof IdentifiableEntity)) return false;
IdentifiableEntity entity = (IdentifiableEntity) o;
if (!super.equals(o)) return false;
if (id != null) {
if (!id.equals(entity.id)) return false;
} else {
if (entity.id …Run Code Online (Sandbox Code Playgroud) 我的问题是为什么WHERE运营商的工作速度不如预期的那么快?考虑我有7个带标签的节点Consumer.这是一些示例数据......
MERGE (c:Consumer {mobileNumber: "000000000000"})
MERGE (:Consumer {mobileNumber: "111111111111"})
MERGE (:Consumer {mobileNumber: "222222222222"})
MERGE (:Consumer {mobileNumber: "333333333333"})
MERGE (:Consumer {mobileNumber: "444444444444"})
MERGE (:Consumer {mobileNumber: "555555555555"})
MERGE (:Consumer {mobileNumber: "666666666666"})
WITH c
MATCH (c1:Consumer) WHERE c1.mobileNumber <> "000000000000"
MERGE (c)-[:HAS_CONTACT]->(c1)
Run Code Online (Sandbox Code Playgroud)
并且HAS_CONTACT在:Consumer(mobileNumber:{"000000000000"})所有其他6个节点之间存在关系.unique index对mobileNumber场地也有约束.现在当我尝试执行以下查询时:
PROFILE MATCH (n:Consumer{mobileNumber : "000000000000"}),
(m:Consumer{mobileNumber : "111111111111"})
WITH n,m
MATCH path = SHORTESTPATH((n)-[contacts:HAS_CONTACT]-(m))
RETURN contacts;
Run Code Online (Sandbox Code Playgroud)
所以它的工作正常如预期(基于唯一索引的搜索节点).以下是其结果:

现在让我们使用WHERE子句更改以上查询:
PROFILE MATCH (n:Consumer{mobileNumber : "000000000000"}),
(m:Consumer) WHERE …Run Code Online (Sandbox Code Playgroud) 我无法在我的界面中为 Neo4j 空间插件导入JavaSpatialRepository和GraphRepositoryJava。
我必须使用neo4j-spatial 插件将多边形数据添加到neo4j 数据库中。为此我使用wkt 格式。但是由于我的 pom.xml 中的版本不匹配,没有导入任何内容。
我曾尝试更改空间插件的版本,但仍然无济于事。我正在使用嵌入式驱动程序。
我正在添加完整的 pom.xml 配置。
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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.neo4j</groupId>
<artifactId>Neo4j</artifactId>
<version>0.25.5-neo4j-3.3.5</version>
<packaging>jar</packaging>
<name>Neo4j</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.3.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId> …Run Code Online (Sandbox Code Playgroud) 我知道,我们可以通过单击“就绪”按钮将 neo4j 数据库导出到 CSV 文件。在我们实现这个密码查询之后:
Match (n)
return n
Run Code Online (Sandbox Code Playgroud)
但这个查询为我们提供了 1 行的所有属性。
我的问题是:在导出到 CSV 文件之前要实现哪个 Cypher 查询,以便为我们提供单独列中的所有属性,即使节点没有相同的属性,
例如:
node(0) has: name, age.
node(1) has: name, age.
node(2) has: name, address.
node(3) has: name, phone No.
node(4) has: name, age.
node(5) has: name, DoB.
Run Code Online (Sandbox Code Playgroud)
我需要的结果是:
name age address phone No DoB
Tom 22
Smith 18
Lee 123abc
Perry 01234
Sara 40
Tom 11/11/2000
Run Code Online (Sandbox Code Playgroud)
不如下:
n
Tom, 22
Smith, 18
Lee, 123abc
Perry, 01234
Sara, 40
Tom, 11/11/2000
Run Code Online (Sandbox Code Playgroud) 我正在将 Spring Data Neo4j 与 Springboot 一起使用,并且该应用程序可以正常工作。
但是,如果可能,我想在启动时删除大量警告。
2019-09-08 14:15:20.788 WARN 10121 --- [ restartedMain] o.s.d.n.mapping.Neo4jPersistentProperty : Owning ClassInfo is null for property: org.apache.commons.logging.Log.fatalEnabled
2019-09-08 14:15:20.789 WARN 10121 --- [ restartedMain] o.s.d.n.mapping.Neo4jPersistentProperty : Owning ClassInfo is null for property: org.apache.commons.logging.Log.errorEnabled
2019-09-08 14:15:20.790 WARN 10121 --- [ restartedMain] o.s.d.n.mapping.Neo4jPersistentProperty : Owning ClassInfo is null for property: org.apache.commons.logging.Log.infoEnabled
2019-09-08 14:15:20.790 WARN 10121 --- [ restartedMain] o.s.d.n.mapping.Neo4jPersistentProperty : Owning ClassInfo is null for property: org.apache.commons.logging.Log.debugEnabled
2019-09-08 14:15:20.790 WARN 10121 --- [ restartedMain] o.s.d.n.mapping.Neo4jPersistentProperty …Run Code Online (Sandbox Code Playgroud) 为了排除实体的一些字段,我创建了一个接口投影,它仅返回一些字段。
我想在存储库接口(扩展Neo4jRepository)中添加一个方法,该方法使用用 Cypher 编写的自定义查询(使用@Query注释)
如果我将返回对象设置为实体,则此方法有效,但当null返回对象设置为投影时,该方法会返回。投影与普通存储库方法一起使用(无需自定义查询)
示例代码: 另外 - 我使用 lombok 但我怀疑它在这里有什么区别
PersonEntity.java
@NodeEntity
@Data
public class Person {
@Id
@GeneratedValue
private Long id;
@Property("first_name")
private String firstName;
@Property("last_name")
private String lastName;
@Property("is_man")
private boolean isMan;
Run Code Online (Sandbox Code Playgroud)
PersonProjection.java
public interface PersonProjection {
Long getId();
String getFirstName();
boolean getIsMan();
}
Run Code Online (Sandbox Code Playgroud)
PersonRepository.java
public interface PersonRepository extends Neo4jRepository<Person, Long> {
@Query("MATCH (n:`Person`) WHERE n.`is_man` = true WITH n RETURN n")
List<PersonProjection> findMen(); // doesn't work, returns null
List<PersonProjection> findAllByIsManTrue(); …Run Code Online (Sandbox Code Playgroud) 自 spring-data-neo4j 6.0 以来,@Depth删除了查询方法的注释(DATAGRAPH-1333,commit)。
如何将使用注释的现有 5.3 代码迁移到 6.0?迁移指南中没有提及。
示例用法,记录在5.3.6.RELEASE 参考中:
public interface MovieRepo extends Neo4jRepository<Movie, Long> {
@Depth(1) // Default, load simple properties and its immediately-related objects
Optional<Movie> findById(Long id);
@Depth(0) // Load simple properties only
Optional<Movie> findByProperty1(String property1);
@Depth(2) // Load simple properties, immediately-related objects and their immediately-related objects
Optional<Movie> findByProperty2(String property2);
@Depth(-1) // Load whole relationship graph
Optional<Movie> findByProperty3(String property3);
}
Run Code Online (Sandbox Code Playgroud)
自定义查询是唯一的选择还是有替代方案?