Congratulations, you have found a 'quirk' AKA 'bug'.

You're creating indexes correctly, but Orient isn't actually using them,
courtesy of the bug.

In short, graph.addVertex() is creating the node, since it has no
properties. If you had set the individual properties one at a time, the
setProperty() call would internally call save() on the node, which would
trip the index check.  Unfortunately, the setProperties() call doesn't
save() internally -- yet. Instead it just updates the document.

In the short term, I would suggest restructuring your code like this:

        OrientGraph graph = factory.getTx()
        for (int i=0;i<10000;i++) {
            try {
                Map<String,Object> props = new HashMap<String,Object>();
                props.put("name", "Jill");
                props.put("age", 33);

                // Set everything at once
                OrientVertex v1 = graph.addVertex("class:Person", props );

                // OR create and then set and then save
                OrientVertex v1 = graph.addVertex("class:Person" );
                v1.setProperties( props );
                v1.save();

                graph.commit();

            } catch (Exception e) {
                log.error("${e.message}");
                graph.rollback();
            }
        }

You should also pile onto #4066 (below).

Related issues:

https://github.com/orientechnologies/orientdb/issues/4066 -- Exists in 2.0.7
https://github.com/orientechnologies/orientdb/issues/3844 -- Fixed in 2.1rc1

On Thu, May 14, 2015 at 9:42 AM, Timm Baumeister <[email protected]>
wrote:

> Unfortunately I still get the same result when using either method. Here
> the new test code:
>
>
> import java.util.HashMap;
> import java.util.Iterator;
> import java.util.Map;
>
> import com.orientechnologies.orient.core.metadata.schema.OType;
> import com.orientechnologies.orient.core.sql.OCommandSQL;
> import com.tinkerpop.blueprints.Vertex;
> import com.tinkerpop.blueprints.impls.orient.*;
>
> public class OrientDBTest {
> public final static String url = "memory:test";//"plocal:c:/tmp/orientdb"
> public static void main(String[] args) {
> OrientGraphFactory factory = new OrientGraphFactory(url, "admin", "admin");
> // ... create database ...
> OrientGraphNoTx graphNoTx = factory.getNoTx();
> OrientVertexType person = graphNoTx.createVertexType("Person");
> person.createProperty("name", OType.STRING);
> person.createProperty("age", OType.INTEGER);
> // final Parameter<?, ?> UNIQUE_INDEX = new Parameter<String,
> String>("type", "UNIQUE_HASH_INDEX");
> // graphNoTx.createKeyIndex("name", Vertex.class, new Parameter<String,
> String>("class", "Person"), UNIQUE_INDEX);
> // person.createIndex("person.nameIdx", OClass.INDEX_TYPE.UNIQUE, "name");
> OCommandSQL cmd = new OCommandSQL();
> cmd.setText("create index Person.name on Person (name) unique" );
> graphNoTx.command(cmd).execute();
> graphNoTx.shutdown();
>
> // ... populate data ...
> OrientGraph graph = factory.getTx();
> long t = System.currentTimeMillis();
> for (int i=0;i<10000;i++) {
> OrientVertex v1 = graph.addVertex("class:Person");
>  Map<String,Object> props = new HashMap<String,Object>();
> props.put("name", "Jill");
> props.put("age", 33);
> v1.setProperties(props);
> if (i%1000==0)
> graph.commit();
> }
> graph.commit();
> System.out.println("Time: "+(System.currentTimeMillis()-t));
> Iterator<Vertex> it = graph.getVerticesOfClass("Person").iterator();
> System.out.println(it.next().getProperty("name") + " "
> +it.next().getProperty("name"));
> graph.shutdown();
>
> }
> }
>
> Now it does not complain any more about doing schema changes in a
> transaction but still no enforcement of the constraint:
>
> May 14, 2015 9:36:26 AM com.orientechnologies.common.log.OLogManager log
> INFO: OrientDB auto-config DISKCACHE=1,276MB (heap=494MB os=3,819MB
> disk=32,320MB)
> Time: 609
> May 14, 2015 9:36:27 AM com.orientechnologies.common.log.OLogManager log
> INFO: - closing storage: test...
> Jill Jill
>
> I am using 2.0.8. Should I revert to an older version to try this?
>
> Timm
>
>  --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "OrientDB" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to