使用neo4j的spring数据rest:如何删除关系
我试图创建一个示例,说明如何使用SpringDataREST服务删除neo4j上的关系。您可以使用来测试 如果我得到关于第一个人的信息,我会看到一部电影使用neo4j的spring数据rest:如何删除关系,neo4j,spring-data-rest,spring-data-neo4j,spring-data-neo4j-4,Neo4j,Spring Data Rest,Spring Data Neo4j,Spring Data Neo4j 4,我试图创建一个示例,说明如何使用SpringDataREST服务删除neo4j上的关系。您可以使用来测试 如果我得到关于第一个人的信息,我会看到一部电影 curl -s http://localhost:8080/persons/1 { "name" : "Keanu Reeves", "born" : 1964, "_links" : { "self" : { "href" : "http://localhost:8080/persons/1" },
curl -s http://localhost:8080/persons/1
{
"name" : "Keanu Reeves",
"born" : 1964,
"_links" : {
"self" : {
"href" : "http://localhost:8080/persons/1"
},
"person" : {
"href" : "http://localhost:8080/persons/1"
},
"movies" : {
"href" : "http://localhost:8080/persons/1/movies"
}
}
}
更改实体后,仍存在以下关系:
curl -s -X PUT -H "Content-Type:application/json" -d '{ "name" : "Keanu Reeves", "born":1964, "movies": [] }' http://localhost:8080/persons/1
{
"name" : "Keanu Reeves",
"born" : 1964,
"_links" : {
"self" : {
"href" : "http://localhost:8080/persons/1"
},
"person" : {
"href" : "http://localhost:8080/persons/1"
},
"movies" : {
"href" : "http://localhost:8080/persons/1/movies"
}
}
}
偶数curl-s-X删除http://localhost:8080/persons/1/movies
无效。那么,如何删除neo4j与spring数据rest之间的关系呢
[Update 1]我试图找到它,但结果是->修复了HashSet和HashCode方法的问题
[Update 2]创建了一个显示Neo4j OGM工作正常,但Spring数据带来了麻烦。->修复-问题是缺少一个@Transactional
,因此每次调用存储库时,都会创建一个新的事务和会话。对于更新,加载和保存必须在同一事务中
[更新3]在解决其他问题后,我能够理解问题。在补丁请求中,对象加载到不同的会话中,然后加载到save方法中。行为如下:在会话[412]中加载对象,以预期方式操作对象,然后在会话[417]中保存对象。有一个设置可在Spring Boot应用程序中启用OpenSessionInViewInterceptor。属性:
spring.data.neo4j.open-in-view=true
这只适用于常规控制器,而不适用于Spring数据REST资源
您可以提供以下配置来启用Spring数据REST的拦截器(在任何@configuration
类中):
谢谢-这两个信息都应该进入参考指南。
@Bean
public OpenSessionInViewInterceptor openSessionInViewInterceptor() {
return new OpenSessionInViewInterceptor();
}
@Bean
public MappedInterceptor myMappedInterceptor() {
return new MappedInterceptor(new String[]{"/**"}, openSessionInViewInterceptor());
}