neo4j : Cannot perform data updates in a transaction that has performed schema updates

☆樱花仙子☆ 提交于 2019-12-08 02:14:57

问题


Hi I am getting following error while saving NodeEntity object by using Neo4jTemplate

Cannot perform data updates in a transaction that has performed schema updates

Spring-data :-

        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>3.1.0.BUILD-SNAPSHOT</version>

Neo4j Version : 2.X

Service :-

@Override
@Transactional
public void addRepository(Repository repository) {
    template.save(repository);
}

Caused by: org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException: Cannot perform data updates in a transaction that has performed schema updates. at org.neo4j.kernel.impl.api.KernelTransactionImplementation$TransactionType$2.upgradeToDataTransaction(KernelTransactionImplementation.java:452) at org.neo4j.kernel.impl.api.KernelTransactionImplementation.upgradeToDataTransaction(KernelTransactionImplementation.java:212) at org.neo4j.kernel.impl.api.KernelStatement.dataWriteOperations(KernelStatement.java:84) at org.neo4j.kernel.InternalAbstractGraphDatabase.createNode(InternalAbstractGraphDatabase.java:1033) ... 49 more


回答1:


SDN 3.0.0 needs now to have base-package configured in your Spring configuration.
Indeed, this is now needed since Neo4j 2.0.X doesn't allow insertion of index (schema change involved by your first save operation) in the same transaction as a data update (save of your entity in your case).

So if you use XML configuration for Spring, it would looks like:

<neo4j:config graphDatabaseService="graphDatabaseService" base-package="com.myApp.myDomainPackage" />

where com.myApp.myDomainPackage contains all the node entities. instead of simple:

<neo4j:config graphDatabaseService="graphDatabaseService"/>



回答2:


Data updates and schema changes need to happen in separate transactions. If they would be allowed in the same transaction various sorts of weirdness would be possible.



来源:https://stackoverflow.com/questions/22089640/neo4j-cannot-perform-data-updates-in-a-transaction-that-has-performed-schema-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!