ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java.lang.IllegalStateException: The vertex or type is not associated with this transaction

2020-02-24 12:03:50  阅读:408  来源: 互联网

标签:lang ParentRunner transaction java person org associated junit runners


经过

给字段建索引时,报异常。
java.lang.IllegalStateException: The vertex or type is not associated with this transaction [person_name]

代码

StandardJanusGraph standardGraphFactory = GraphUtil.getStandardGraphFactory();
        JanusGraphManagement mgmt = standardGraphFactory.openManagement();
        VertexLabel person = mgmt.getVertexLabel("person");
        PropertyKey name = mgmt.getPropertyKey("person_name");
        mgmt = standardGraphFactory.openManagement();
        mgmt.buildIndex("person_name_index", Vertex.class).addKey(name).buildCompositeIndex();
        mgmt.commit();
        GraphTraversalSource g = standardGraphFactory.traversal();
        g.addV("person").property("birthDate", new Date(), "person_name", "limin");
        g.tx().commit();

异常信息

java.lang.IllegalStateException: The vertex or type is not associated with this transaction [person_name]

	at org.janusgraph.graphdb.transaction.StandardJanusGraphTx.verifyAccess(StandardJanusGraphTx.java:287)
	at org.janusgraph.graphdb.transaction.StandardJanusGraphTx.verifyWriteAccess(StandardJanusGraphTx.java:279)
	at org.janusgraph.graphdb.transaction.StandardJanusGraphTx.addEdge(StandardJanusGraphTx.java:701)
	at org.janusgraph.graphdb.transaction.StandardJanusGraphTx.addSchemaEdge(StandardJanusGraphTx.java:903)
	at org.janusgraph.graphdb.database.management.ManagementSystem.addSchemaEdge(ManagementSystem.java:231)
	at org.janusgraph.graphdb.database.management.ManagementSystem.createCompositeIndex(ManagementSystem.java:691)
	at org.janusgraph.graphdb.database.management.ManagementSystem.access$300(ManagementSystem.java:79)
	at org.janusgraph.graphdb.database.management.ManagementSystem$IndexBuilder.buildCompositeIndex(ManagementSystem.java:759)
	at cn.haizhi.bigdata.graph.client.DataInsertTest.testInsertDateData(DataInsertTest.java:59)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

问题排查

原因是建索引的时候,用的不是首次standardGraphFactory.openManagement()打开的事务,所以会报这个异常。只需要把后面的代码mgmt = standardGraphFactory.openManagement();注释掉就OK了。
即:

```java
StandardJanusGraph standardGraphFactory = GraphUtil.getStandardGraphFactory();
        JanusGraphManagement mgmt = standardGraphFactory.openManagement();
        VertexLabel person = mgmt.getVertexLabel("person");
        PropertyKey name = mgmt.getPropertyKey("person_name");
        mgmt.buildIndex("person_name_index", Vertex.class).addKey(name).buildCompositeIndex();
        mgmt.commit();
        GraphTraversalSource g = standardGraphFactory.traversal();
        g.addV("person").property("birthDate", new Date(), "person_name", "limin");
        g.tx().commit();
汐朔 发布了38 篇原创文章 · 获赞 18 · 访问量 21万+ 私信 关注

标签:lang,ParentRunner,transaction,java,person,org,associated,junit,runners
来源: https://blog.csdn.net/arlanhon/article/details/104474530

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有