简体   繁体   中英

OrientDB getVertices not working with Java-generated class/index

Summary

I'm playing around with OrientDB for a proof of concept, and I'm having some trouble querying a class/composite index generated through the Java API.

I created the class, added a few properties and generated the composite index using the API, then added a sample record. I verified that everything looked okay using the Studio. I then used getVertices(String label, String[] keys, Object[] values) to try to pull my sample record, but didn't get any results.

I purged the index and class and recreated them using the Studio UI, ran the getVertices code and the record was retrieved successfully.

In the course of my investigation, I also recreated the class/index using the Java API and provided an incorrect label (a class created via the UI that extended V) and the record was retrieved successfully, which was weird.

Why is the the Java-created class/index behaving differently than the one I made in the UI? Am I doing something wrong?

Environment Background

I'm using OrientDB Enterprise 2.0.3 and the 2.0.x orientdb-* and blueprints-core jars.

Details

I'm creating the class/index in Java kind of like this (shortened for simplicity, strings changed to protect the innocent):

//graph is an OrientGraph

//Create a new class that extends V
OClass vt = graph.createVertexType("MyClass", "V");

String[] props = {"first", "second", "third"}; //Property names

for(String prop : props)
  vt.createProperty(prop, OType.STRING);

//Create unique composite index using all properties
vt.createIndex("myClass.myIndex", OClass.INDEX_TYPE.UNIQUE, props);

graph.commit();

I added records to the graph like this and confirmed that they showed up in Studio (select * from MyClass):

Vertex v = graph.addVertex("class:MyClass");
v.setProperty("first", "foo");
v.setProperty("second", "bar");
v.setProperty("third", "ed");

graph.commit();

To query the graph, I'm using this:

String[] keys = {"first", "second", "third"};
String[] values = {"foo", "bar", "ed"};

//Using getVertices to get records from a specific class with specified key values.
//There could be multiple classes with the same properties, so I have to be able
//to look for a set of properties within a specific class.
Iterable<Vertex> resultIterator = graph.getVertices("MyClass", keys, values);

for (Vertex v : resultIterator){
    results.add(v); //Store result references for later use
}

Also, I did confirm that graph.isUseClassForVertexLabel() was true.

When I run graph.getVertices("MyClass",keys,values) , nothing comes back.

If I run graph.getVertices("DummyClass",keys,values) where DummyClass is a random class created in Studio that extends V and has completely different properties than MyClass, I get results. This case kind of scares me, because there could eventually be multiple classes with the same properties, and I have to be able to query records from a specific class with a property set - I don't want to pull in results from a bunch of different classes...

If I recreate MyClass from the Studio UI and run graph.getVertices("MyClass",keys,values) , I get the expected results.

I created an issue ( #3889 ) for this on the OrientDB repo. It has been fixed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM