由于node_auto_index,无法删除节点

时间:2013-09-06 15:52:13

标签: java neo4j spring-data-neo4j

我正在尝试从图表中删除一个节点,但是我收到了这个例外:

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才能删除自动索引节点,或者我的配置中是否遗漏了某些内容?

1 个答案:

答案 0 :(得分:0)

是的,我认为禁用自动索引是最好的选择。