How to insert JSON with Java Graph API?

55 views
Skip to first unread message

Academia Learning Centro de inglés y de formación

unread,
Nov 17, 2016, 9:11:52 AM11/17/16
to OrientDB
I'm doing it like this

Vertex pruebaJson = graph.addVertex("class:Person");
JSONObject json = new JSONObject();

json.put("name","someone");
json.put("address","somewhere");
json.put("value","{'archetype_details':{'class':'ARCHETYPED','archetype_id':{'class':'ARCHETYPE_ID','value':'openEHR-EHR-COMPOSITION.report-mnd.v1'},'template_id':{'class':'TEMPLATE_ID','value':'Laboratory Report'},'rm_version':'1.0.1'}}");

pruebaJson.setProperty("data", json.toString());

This works but inserts it as a string inside the vertex instead of as an embedded document, and then I can not use the type queries:
Select * from Person where data.name = 'someone'

How can I make it to insert it as an embedded document instead of as a text string?

alessand...@gmail.com

unread,
Nov 17, 2016, 9:45:42 AM11/17/16
to OrientDB
Hi, you could try with

OrientGraph g=new OrientGraph(yourPath);
 
ODocument pruebaJson = new ODocument("Person");

JSONObject json = new JSONObject();

json
.put("name","someone");
json
.put("address","somewhere");
json
.put("value","{'archetype_details':{'class':'ARCHETYPED','archetype_id':{'class':'ARCHETYPE_ID','value':'openEHR-EHR-COMPOSITION.report-mnd.v1'},'template_id':{'class':'TEMPLATE_ID','value':'Laboratory Report'},'rm_version':'1.0.1'}}");


pruebaJson
.fromJSON("{ 'data' : " + json.toString() + "}");
pruebaJson
.save();
 
g
.commit();


Message has been deleted

Academia Learning Centro de inglés y de formación

unread,
Nov 21, 2016, 8:31:45 AM11/21/16
to OrientDB
How can I convert that document class to graph then? If I can not create edges

alessand...@gmail.com

unread,
Nov 21, 2016, 10:02:08 AM11/21/16
to OrientDB
You could use

alter class yourclass superclasses v


Academia Learning Centro de inglés y de formación

unread,
Nov 22, 2016, 3:20:37 AM11/22/16
to OrientDB
I do not understand what you mean, sorry.

I created a document to insert a json, but how do I insert this in my vertex?

Academia Learning Centro de inglés y de formación

unread,
Nov 22, 2016, 5:02:46 AM11/22/16
to OrientDB
Help, I need to create two vertices with json content and then join them using an edge
Reply all
Reply to author
Forward
0 new messages