orientechnologies / orientdb

OrientDB is the most versatile DBMS supporting Graph, Document, Reactive, Full-Text and Geospatial models in one Multi-Model product. OrientDB can run distributed (Multi-Master), supports SQL, ACID Transactions, Full-Text indexing and Reactive Queries.
https://orientdb.dev
Apache License 2.0
4.72k stars 870 forks source link

Graph API: getVertexByKey not working #4042

Closed johansjob closed 9 years ago

johansjob commented 9 years ago

I have a HashIndex on one of my classes, lets call it Cars. Using the graph api I want to get a vertex, I've tried the following two methods:

Vertex vertex = graph.getVertexByKey("Cars.nameHash", "Volvo"); 
Vertex vertex2 = graph.getVertices("Cars.nameHash", "Volvo").iterator().next();

The getVertices returns a vertex like it should by the getVertexByKey does not (it is null). So I checked the source code a bit. It turns out that the getVertexByKey function gets the index, idx and the uses the get function:

Object v = idx.get(iValue);

This object is then passed to the normal getVertex function which takes an id as a String/ODocument/OIdentifiable. The problem is that the get function actually return a HashSet with ids. The getVertex can't handle hashsets (like intended) and thus returns null.

In my quick test the HashSet was of size one, not sure if that will always be the case though, but overall this should be a quick fix.

wolf4ood commented 9 years ago

hi @johansjob from the code i see that this api is supposed to work with unique index. Which index are you using?

johansjob commented 9 years ago

Oh that might have been the problem, we were using a NOTUNIQUE_HASH_INDEX I suppose it is my bad for expecting a vertex then.. Perhaps a small clarification to the JavaDoc or a better error could help sort out any misunderstanding.

wolf4ood commented 9 years ago

Yes @johansjob i'm changing the JavaDoc