我试图从图中删除一个节点,但我收到了这个异常:
java.lang.UnsupportedOperationException: read only index
at org.neo4j.kernel.AbstractAutoIndexerImpl$ReadOnlyIndexToIndexAdapter.readOnlyIndex(AbstractAutoIndexerImpl.java:253) ~[neo4j-kernel-1.9.jar:1.9]
at org.neo4j.kernel.AbstractAutoIndexerImpl$ReadOnlyIndexToIndexAdapter.remove(AbstractAutoIndexerImpl.java:283) ~[neo4j-kernel-1.9.jar:1.9]
at org.springframework.data.neo4j.support.DelegatingGraphDatabase.removeFromIndexes(DelegatingGraphDatabase.java:107) ~[spring-data-neo4j-2.3.0.RC1.jar:na]
at org.springframework.data.neo4j.support.DelegatingGraphDatabase.remove(DelegatingGraphDatabase.java:246) ~[spring-data-neo4j-2.3.0.RC1.jar:na]
at org.springframework.data.neo4j.support.mapping.EntityRemover.removeNode(EntityRemover.java:53) ~[spring-data-neo4j-2.3.0.RC1.jar:na]
at org.springframework.data.neo4j.support.mapping.EntityRemover.removeNodeEntity(EntityRemover.java:45) ~[spring-data-neo4j-2.3.0.RC1.jar:na]
at org.springframework.data.neo4j.support.mapping.EntityRemover.remove(EntityRemover.java:85) ~[spring-data-neo4j-2.3.0.RC1.jar:na]
at org.springframework.data.neo4j.support.Neo4jTemplate.delete(Neo4jTemplate.java:222) ~[spring-data-neo4j-2.3.0.RC1.jar:na]
at org.springframework.data.neo4j.repository.AbstractGraphRepository.delete(AbstractGraphRepository.java:328) ~[spring-data-neo4j-2.3.0.RC1.jar:na]
at org.springframework.data.neo4j.repository.AbstractGraphRepository.delete(AbstractGraphRepository.java:333) ~[spring-data-neo4j-2.3.0.RC1.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_25]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_25]
经过一些调试,我发现这是在尝试从node_auto_index
.
该图已经设置了节点和关系的自动索引,这些自动索引是在使用 neo4j 独立服务器(版本 1.9.M03)启动图时创建的。这是关于neo4j.properties
# Keep logical logs, helps debugging but uses more disk space, enabled for legacy reasons
# To limit space needed to store historical logs use values such as: "7 days" or "100M size"
# instead of "true"
keep_logical_logs=true
# Autoindexing
# Enable auto-indexing for nodes, default is false
node_auto_indexing=true
# The node property keys (comma separated) to be auto-indexed, if enabled
node_keys_indexable=key,name,value,email,type
# Enable auto-indexing for relationships, default is false
relationship_auto_indexing=true
# The relationship property keys to be auto-indexed, if enabled
relationship_keys_indexable=name,age,value
这是我的 SDN-Neo4j 配置:
@Configuration
@EnableTransactionManagement // mode = proxy
@EnableNeo4jRepositories(basePackages = "graph.repository")
@ComponentScan({
"graph.component",
"graph.service",
"core.service"
})
public class Neo4jConfig extends Neo4jConfiguration {
private static final String DB_PATH = "path_to.db";
private static final String CONFIG_PATH = "path_to.properties";
@Bean(destroyMethod = "shutdown")
public GraphDatabaseService graphDatabaseService() {
return new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(DB_PATH)
.loadPropertiesFromFile(CONFIG_PATH).newGraphDatabase();
}
}
这就是我如何尝试删除节点
@NodeEntity
public class CustomEntity {
@GraphId
Long id;
private String someProperty;
...
public Long getId() { return this.id; }
public CustomEntity setId(Long id) { this.id = id; return this; }
...
}
public interface CustomRepository extends GraphRepository<CustomEntity> {
...
}
@Service
public class CustomService {
@Inject
private CustomRepository repoCust;
@Transactional
public void delete(long custId) {
this.repoCust.delete(custId);
}
}
在使用 SDN-Neo4j 时,我是否必须禁用自动索引才能删除自动索引节点,或者我是否遗漏了配置中的某些内容?