帮我解决这个问题 我正在通过此代码创建Db
创建数据库
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
Transaction tx = graphDb.beginTx();
try {
/* creating app node and setting properties of the node */
app = graphDb.createNode();
appNodeId = app.getId();
System.out.println("AppNodeId:::::::::::" + appNodeId);
app.setProperty("appId", appPojo.getAppId());
app.setProperty("appName", appPojo.getAppName());
// app.setProperty("userList", appPojo.getUserList());
System.out.println(">>>>app_data" + app.getId());
/* creating user node and setting properties of the node */
user = graphDb.createNode();
user.setProperty("userId", userPojo.getUserId());
user.setProperty("userName", userPojo.getUserName());
user.setProperty("appId", appPojo.getAppId());
System.out.println(">>>>user_data" + user.getId());
/* creating HAS_A relationship between app node and user node */
relationship = app.createRelationshipTo(user, RelTypes.HAS_A)
}
finally {
System.out.println(">>>>>>>>>Finally");
}
DB_PATH是我的本地目录
答案 0 :(得分:1)
启动数据库时,会创建一个锁定文件。如果没有正确关闭它,则不会删除锁定文件。再次启动时,锁定文件已存在,无法创建,并引发异常。尝试从DB_PATH
手动删除锁定文件,并确保下次正确关闭数据库;对于普通情况,您应该显式调用graphDb.shutdown()
,对于例外情况,应该有一个关闭钩子。这就是Neo4j示例代码中的关闭钩子的样子
private static void registerShutdownHook( final GraphDatabaseService graphDb )
{
Runtime.getRuntime().addShutdownHook( new Thread()
{
@Override
public void run()
{
graphDb.shutdown();
}
} );
}