0

我正在使用 Apache Jackrabbit。

我发现了一个异常,我尝试了很多但没有得到这个异常背后的原因。

请帮我解决这个问题。

例外 :-

javax.jcr.RepositoryException: This session has been closed.
    at org.apache.jackrabbit.jcr2spi.SessionImpl.checkIsAlive(SessionImpl.java:922)
    at org.apache.jackrabbit.jcr2spi.ItemImpl.checkStatus(ItemImpl.java:436)
    at org.apache.jackrabbit.jcr2spi.NodeImpl.getProperties(NodeImpl.java:489)
    at edu.uci.ics.crawler4j.frontier.DocIDServer.getDocId(DocIDServer.java:112)
    at edu.uci.ics.crawler4j.crawler.WebCrawler.processPage(WebCrawler.java:286)
    at edu.uci.ics.crawler4j.crawler.WebCrawler.run(WebCrawler.java:189)
    at java.lang.Thread.run(Thread.java:722)

编辑 1

代码如下,

Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server");
Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

// Obtain the query manager for the session via the workspace ...
QueryManager queryManager = session.getWorkspace().getQueryManager();

// Create a query object ...
String expression = "SELECT * FROM [sling:OrderedFolder] AS s WHERE ISDESCENDANTNODE([/docIDsDB])";
Query query = queryManager.createQuery(expression, javax.jcr.query.Query.JCR_SQL2);

// Execute the query and get the results ...
QueryResult result = query.execute();

// Iterate over the nodes in the results ...
NodeIterator nodeIter = result.getNodes();

session.logout();

while(nodeIter.hasNext()){
    Node node = nodeIter.nextNode();
    System.out.println(node.getProperty("url").getString());
    System.out.println(node.getProperty("docid").getString());

}

例外

javax.jcr.RepositoryException: This session has been closed.
    at org.apache.jackrabbit.jcr2spi.SessionImpl.checkIsAlive(SessionImpl.java:922)
    at org.apache.jackrabbit.jcr2spi.ItemImpl.checkStatus(ItemImpl.java:436)
    at org.apache.jackrabbit.jcr2spi.NodeImpl.getProperty(NodeImpl.java:471)
    at jackrabbit.JackRabbit.main(JackRabbit.java:111)

111 号线是

System.out.println(node.getProperty("url").getString());

在 Jackrabbit 中,节点和子节点都是 sling:orderedFolder 类型。

4

2 回答 2

1

只要您访问它提供的节点,就保持 JCR 会话打开。

您应该将 Session.logout() 调用移至 finally 子句,该子句毕竟是使用 Session 提供的所有代码。

于 2013-06-20T07:59:08.600 回答
0

您应该session.isLive()在重用存储之前进行测试Session,并在此方法返回时重新获取它false

于 2013-06-20T10:04:22.110 回答