尝试连接到Neo4J的java程序我遇到了以下错误
/home/mkgs/Desktop/placement/
Mar 21, 2014 2:53:41 PM org.neo4j.kernel.impl.transaction.xaframework.XaLogicalLog doInternalRecovery
INFO: Non clean shutdown detected on log [/home/mkgs/Desktop/placement/nioneo_logical.log.1Recovery started ...
Mar 21, 2014 2:53:42 PM org.neo4j.kernel.impl.transaction.xaframework.XaLogicalLog doInternalRecovery
INFO: Non clean shutdown detected on log [/home/mkgs/Desktop/placement/index/lucene.log.1]. Recovery started ...
Exception in thread "main" java.lang.ClassCastException: org.neo4j.kernel.TopLevelTransaction cannot be cast to javax.transaction.Transaction
at neo.main(neo.java:22)
java代码如下
//import javax.transaction.Transaction;
import javax.transaction.Transaction;
import org.neo4j.cypher.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.kernel.EmbeddedGraphDatabase;
public class neo {
public static void main(String args[])
{
final String DB_PATH = "/home/mkgs/Desktop/placement/";
GraphDatabaseService graphDb;
System.out.println(DB_PATH);
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
Transaction tx = (Transaction) graphDb.beginTx();
try {
ExecutionEngine engine = new ExecutionEngine(graphDb, null);
ExecutionResult result = (ExecutionResult) engine.execute("START
n=node(*) MATCH n-[r]-m RETURN type(r), count(*) ORDER BY count(*) desc");
System.out.println(result);
}
finally {
((org.neo4j.graphdb.Transaction) tx).finish();
}
}
}
答案 0 :(得分:2)
不要使用
import javax.transaction.Transaction;
但请使用
import org.neo4j.graphdb.Transaction;
这就是导致ClassCastException
。