Import fails with 'Cannot drop an index inside a transaction' in an embedded server

I am unable to import a database in an embedded server, I see below exception,

java.lang.IllegalStateException: Cannot drop an index inside a transaction
at com.orientechnologies.orient.core.index.OIndexManagerShared.dropIndex(OIndexManagerShared.java:238)
at com.orientechnologies.orient.core.index.OIndexManagerProxy.dropIndex(OIndexManagerProxy.java:100)
at com.orientechnologies.orient.core.db.tool.ODatabaseImport.removeDefaultNonSecurityClasses(ODatabaseImport.java:412)
at com.orientechnologies.orient.core.db.tool.ODatabaseImport.importDatabase(ODatabaseImport.java:162)

Any export or import options to resolve this issue?

Usually if you create an embedded server you have something like:

            server = OServerMain.create();
            server.startup(getOrientServerConfig());
            server.activate();

you can then do something like:

 ODatabaseDocumentInternal db = server.openDatabase(dbName);
 ODatabaseImport dbImport = new ODatabaseImport(db, "config/schema.gz", listener);
 dbImport.importDatabase();
 dbImport.close();
db.close()

You can also do this with a graph factory instance:

ODatabaseDocumentInternal db = (ODatabaseDocumentInternal) getFactory().getNoTx().getRawDatabase();

Thanks for the reply Jon, but my problem is different when I call dbImport.importDatabase(); I get an exception - java.lang.IllegalStateException: Cannot drop an index inside a transaction.

I want a resolution for this issue.

Can you post the code ? I think this may be related to how you open the db instance. Are you using a non-tx graph instance?

ODatabaseDocumentTx dbtx = m_orientGraph.getRawGraph();
    OCommandOutputListener listener = new OCommandOutputListener() {
        @Override
        public void onMessage(String iText) {
            logger.error(iText);
        }
    };
    ODatabaseImport imprt = new ODatabaseImport(dbtx, sImportFilename, listener);
    imprt.setVerbose(true);
    imprt.setRebuildIndexes(false);
    imprt.setMerge(false);
    /*imprt.setDeleteRIDMapping(true);
    imprt.setMerge(false);
    imprt.setDeleteRIDMapping(true);*/
    imprt.importDatabase();
    imprt.close();

FYI, I am not using a non-tx graph instance.

hm looks fine. I highly assume, as you set “merge” to false your import overrides everything and therefore tries to drop the existing indexes which is obviously not allowed in a transaction. Have you tried using a non-tx graph once?

Thanks Jon, I tried setting the “Merge” flag as true and it stopped failing with the exception but now seeing another one

com.orientechnologies.orient.core.exception.ODatabaseException:  Impossible to remove the last cluster of class 'Group' drop the class instead
DB name="cachedb1"
at com.orientechnologies.orient.core.metadata.schema.OClassImpl.removeClusterId(OClassImpl.java:1219)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.dropCluster(ODatabaseDocumentTx.java:1460)
at com.orientechnologies.orient.core.db.tool.ODatabaseImport.importClusters(ODatabaseImport.java:929)
at com.orientechnologies.orient.core.db.tool.ODatabaseImport.importDatabase(ODatabaseImport.java:179)

which orientdb version are you using?

2.2.34 Community edition.

I would recommend updating. Not only because 2.2.x is deprecated (3.1. recent GA) but it seems there was a bug causing your issue: