我正在使用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中,节点和子节点都是吊索:orderedFolder类型。
答案 0 :(得分:1)
只要您访问它提供的节点,就可以保持JCR会话处于打开状态。
您应该将Session.logout()调用移动到finally子句,该子句位于使用Session提供的所有代码之后。
答案 1 :(得分:0)
您应该在重用已存储的session.isLive()
之前测试Session
,并在此方法返回false
时重新获取它。