최근에 그래프 데이터베이스 (특히 Neo4j 및 OrientDB)를 탐색하기 시작했으며 내 손가락을 대고있을 수없는 문제가 발생했습니다.OrientDB에서 특정 클래스의 모든 정점 나열하기
로컬 설치 OrientDB (OrientDB Server v2.0-M3가 사용 중입니다.)가 실행 중입니다. Tinkerpops를 사용하여 그래프에 연결하고 쿼리를 실행하고 있습니다. 로컬 Tomcat 7 서버에서 Java 및 Spring을 사용하고 있습니다. API 테스트 Chrome에서 우편 배달부를 사용하고 있습니다. 나는 오류가 제안하는 것이 "수정"노력이를 알아 내기 위해 노력했습니다
{
"timestamp": 1418562889304,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.http.converter.HttpMessageNotWritableException",
"message": "Could not write JSON: Database instance is not set in current thread. Assure to set it with: ODatabaseRecordThreadLocal.INSTANCE.set(db); (through reference chain: java.util.Vector[0]->$Proxy43[\"name\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Database instance is not set in current thread. Assure to set it with: ODatabaseRecordThreadLocal.INSTANCE.set(db); (through reference chain: java.util.Vector[0]->$Proxy43[\"name\"])",
"path": "/articles"
}
:
이@RequestMapping(value = "/articles", method = RequestMethod.GET)
public
@ResponseBody
Vector<Article> list() {
OrientGraph graph = new OrientGraph("remote:/local/path/to/orientdb/databases/mydb", "user", "password");
FramedGraphFactory factory = new FramedGraphFactory();
FramedGraph manager = factory.create(graph);
Vector<Article> articles = new Vector<>();
try {
Iterable<Vertex> vertices = graph.getVerticesOfClass("Article", false);
Iterator<Vertex> it = vertices.iterator();
if (it.hasNext()) {
do {
Article a = (Article) manager.frame(it.next(), Article.class);
articles.add(a);
} while (it.hasNext());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
graph.shutdown();
}
return articles;
}
이것은 다음과 같은 오류가 발생
은 여기 내 결함 GET 방식입니다. 또한 OrientGraph 대신 TransactionalGraph를 사용하려고했습니다.
여기 잡기가 있습니다 ... 저는 또한 하나의 리소스를 얻는 데에도 비슷한 방법을 사용하고 있습니다. 이 메서드 "System.out.println"을 사용하는 경우에만 작동합니다. 그렇지 않으면 동일한 오류와 함께 실패합니다.
@RequestMapping(value = "/article", method = RequestMethod.GET)
public
@ResponseBody
Article get(
@RequestParam(value = "number", required = true) long number
) {
TransactionalGraph graph = new OrientGraph("remote:/path/to/local/orientdb/orientdb/databases/mydb", "user", "password");
FramedGraphFactory factory = new FramedGraphFactory();
FramedGraph manager = factory.create(graph);
Article article = null;
try {
Iterable<Article> articles = manager.getVertices("number", number, Article.class);
article = articles.iterator().next();
System.out.println(article.getName());
} catch (Exception e) {
e.printStackTrace();
} finally {
graph.shutdown();
}
return article;
}
도움을 주시면 감사하겠습니다.
종료 전에 JSON을 반환하면 그래프 연결을 무기한 열어 두지 않을까요? – Andreas
try {} 블록 내부에서 return을 삭제하려고합니다. – Lvca