Inconsistent vertex persist after remove edge with MMAPI

Hi. I’m dealing with an issue that i could not isolate.
When I remove an edge from v1 to v2 and add a new edge to v3 I get an inconsistent vertex V1.
Unfortunately I could not create the same behavior with a custom case, but I get it always when I test my app.
Look up this code:

        LOGGER.log(Level.FINEST, "--->");
        LOGGER.log(Level.FINEST, "edges pre-save: "+this.___baseElement.asVertex().get().getEdges(ODirection.OUT, "SimpleVertexEx_looptest"));
        LOGGER.log(Level.FINEST, "--->");
        this.___baseElement.asVertex().get().save();
        LOGGER.log(Level.FINEST, "--->");
        LOGGER.log(Level.FINEST, "edges post-save: "+this.___baseElement.asVertex().get().getEdges(ODirection.OUT, "SimpleVertexEx_looptest"));
        LOGGER.log(Level.FINEST, "--->");

and this is the result:

MÁS DETALLADO[2020/09/10 12:34:43]:net.odbogm.proxy.ObjectProxy doCommit :: --->
MÁS DETALLADO[2020/09/10 12:34:43]:net.odbogm.proxy.ObjectProxy doCommit :: edges pre-save: [1]
MÁS DETALLADO[2020/09/10 12:34:43]:net.odbogm.proxy.ObjectProxy doCommit :: --->
MÁS DETALLADO[2020/09/10 12:34:44]:net.odbogm.proxy.ObjectProxy doCommit :: --->
MÁS DETALLADO[2020/09/10 12:34:44]:net.odbogm.proxy.ObjectProxy doCommit :: edges post-save: [2]
MÁS DETALLADO[2020/09/10 12:34:44]:net.odbogm.proxy.ObjectProxy doCommit :: --->

In the database I get this:
image

v1: #632:45
v2: #633:44
v3: #618:51

v2 and v3 are correct, but v1 still have the edge #638:8 that was deleted.

If you clic over it, it show this:
image

And if you list the edges

for (OEdge edge : ((IObjectProxy)v1).___getVertex().getEdges(ODirection.OUT, "SimpleVertexEx_looptest")) {
        System.out.println("--: "+edge);
    }

you get this:

   net.odbogm.SessionManagerTest > bug STANDARD_ERROR
   ADVERTENCIA[2020/09/10 12:57:53]:com.orientechnologies.common.log.OLogManager log :: 
   Record (#638:8) is null

   net.odbogm.SessionManagerTest > bug STANDARD_OUT
   --: SimpleVertexEx_looptest#639:8{out:#632:45,in:#618:51} v1

The database store the Vertex in an inconsistent state but if you execute a check database, it say that it is all ok.
If I remove and add another edge to v4 for example, I get two null edges in v1.
How can I fix this?
Thanks.

Marcelo

I have isolate the issue! Check this:

private void testMMAPIinLab() {
    OrientDB orientDB = new OrientDB("remote:localhost",OrientDBConfig.defaultConfig());
    
    OrientDBConfigBuilder poolCfg = OrientDBConfig.builder();
    poolCfg.addConfig(OGlobalConfiguration.DB_POOL_MIN, 5);
    poolCfg.addConfig(OGlobalConfiguration.DB_POOL_MAX, 10);
    //poolCfg.addConfig(OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD, -1);
    ODatabasePool dbPool = new ODatabasePool(orientDB,"lab", "root", "toor", poolCfg.build());
    
    
    ODatabaseSession db = dbPool.acquire();

    db.begin();
    System.out.println("creando el vértice....");
    OVertex v1 = db.newVertex();
    v1.save();
    System.out.println("save rid: "+v1.getIdentity().toString());
    
    OVertex v2 = db.newVertex();
    v2.save();
    System.out.println("v2 save rid: "+v2.getIdentity().toString());

    System.out.println("crear un edge.");
    OEdge oe = v1.addEdge(v2);
    v1.save();
    
    System.out.println("llamando a commit...");
    db.commit();
    db.close();
    
    System.out.println("configuración grabada:");
    System.out.println("v1: "+v1.getIdentity().toString());
    System.out.println("v2: "+v2.getIdentity().toString());
    System.out.println("edge: "+oe.getFrom()+" --> "+oe.getTo());
    
    // abrir otra transacción
    db = dbPool.acquire();
    db.begin();
    System.out.println("crear v3");
    OVertex v3 = db.newVertex();
    v3.save();
    System.out.println("v3 save rid: "+v3.getIdentity().toString());
    
    System.out.println("modificar v1...");
    v1.setProperty("value", "test");
    
    System.out.println("borrar relación con v2");
    // borrar el edge anterior
    Iterator<OEdge> toRemove = v1.getEdges(ODirection.OUT).iterator();
    while (toRemove.hasNext()) {
        OEdge removeEdge = toRemove.next();
        //removeEdge = (OEdge) edge;
        removeEdge.delete();
        removeEdge.save();
    }
    
    System.out.println("agregar una relación de v1 a v3");
    OEdge oe2 = v1.addEdge(v3);
    
    v1.save();

    // crera en edge nuevo a v3
    db.commit();
    
    System.out.println("v1 edges: "+v1.getEdges(ODirection.OUT));
    System.out.println("v3 post-commit rid: "+v3.getIdentity().toString());
    System.out.println("oe2: "+oe2.getFrom()+" --> "+oe2.getTo());
    
    db.close();
    
}

The code create a Vertex in DB that point to an non-existent edge.