Hey,

im trying to save some objects to the database, i have a unique constraint 
defined on my class product. The code looks like this:

graphDbFactory = new OrientGraphFactory("plocal:" + 
server.getDatabaseDirectory() + File.separator + graphDatabase, userName, 
userPassword);
graphInstance = graphDbFactory.getTx();
graphInstance.createKeyIndex("name", Vertex.class, new Parameter("type", 
"UNIQUE"), new Parameter("class", "Product"));
...
// save: this is called twice
try {
    // Graph
    OrientVertex v = graphInstance.addVertex("class:" + 
getGenericClass().getSimpleName()); // 1st operation: implicitly begin a 
transaction
    // String evaluates to class:Product
    v = createVertexFromEntity(entity, v);
    graphInstance.commit(); // commit the transaction
    entity.setId(v.getIdentity().toString());
    return entity;
} catch (OTransactionException e) {
    graphInstance.rollback();
    throw new RuntimeException(e);
}
...

Iterable<Vertex> vertices = graphInstance.getVertices("Product.name", 
name); 

...
// help method
protected OrientVertex createVertexFromEntity(T entity, OrientVertex v) {
        Map<String, Object> properties = new HashMap<>();
    properties.put("name", entity.getName());

    // set properties
     v.setProperties(properties);

    return v;
}

the code in the try/catch block is called twice with two seprated product 
objects having the same name (e.g. "product1").
both products are saved in the database, the constraint won't trigger. if i 
call the graphInstance.getVertices("Product.name", name) i get a emty 
iterator back.

if i rebuild the index later (in studio) i get an error on the duplicate 
key.

Any ideas why this happens? any mistakes in the code above?

-- 

--- 
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