How to get the value of a vertex in json, java graph api?

34 views
Skip to first unread message

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

unread,
Nov 22, 2016, 9:03:20 AM11/22/16
to OrientDB
I am using this but I can not get its json value, only the OrientVertex

Iterable<OrientVertex> resultEhr = graph.command( new OCommandSQL("select from EHR where ehrId = '" + ehrId + "'") ).execute();
    if (resultEhr.iterator().hasNext()){
    Vertex ehr = (Vertex) resultEhr.iterator().next();     
    }


Any suggestions? Thanks!

alessand...@gmail.com

unread,
Nov 22, 2016, 11:11:35 AM11/22/16
to OrientDB
Hi,
you could use

Iterable<OrientVertex> resultEhr = g.command( new OCommandSQL("select @this.toJSON() as this from EHR where ehrId = '" + ehrId + "'") ).execute();

if (resultEhr.iterator().hasNext()){
   Vertex ehr = (Vertex) resultEhr.iterator().next();

   
System.out.println(ehr.getProperty("this"));
}

You get for example 

{"@type":"d","@rid":"#21:0","@version":1,"@class":"EHR","name":"name1","ehrId":"id1"}


Best regards,
Alessandro
Message has been deleted

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

unread,
Nov 23, 2016, 8:57:07 AM11/23/16
to orient-...@googlegroups.com
 Thanks, Could the same be done with the expand function?


SELECT expand (out('hasVersions')).toJson() as this FROM Composition WHERE idComposition = '3'


EDIT:  SELECT @this.toJson('rid') FROM ( SELECT expand (out('hasVersions')) as this FROM Composition WHERE idComposition = '3')
Reply all
Reply to author
Forward
0 new messages