3

我在使用 jcouchdb 索引表/集合时遇到问题。实际上它看起来很简单,但经过一些研究,我不知道问题出在哪里,或者我只是瞎了眼。我跟着官方的测试课:

https://code.google.com/p/orient/source/browse/trunk/tests/src/test/java/com/orientechnologies/orient/test/database/auto/ClassIndexTest.java

看看下面的代码:

public class TestIndex {
    public static final String dbname = "indextest";
    public static final String colname = "object";
    public static final String indexAttribute = "ATTR1";

    public static void main(String[] args)
    {

        //ODatabaseDocumentTx db = new ODatabaseDocumentTx ("local:/tmp/databases/" + dbname).create();
        ODatabaseDocumentTx db = new ODatabaseDocumentTx ("local:/tmp/databases/orienttestdb");
        db.open("admin", "admin");

        try {
            if(db.getMetadata().getSchema().existsClass(colname))
                db.getMetadata().getSchema().dropClass(colname);
            OClass object = db.getMetadata().getSchema().getOrCreateClass((colname));
            object.createProperty(indexAttribute, OType.INTEGER);
            object.createIndex(colname, OClass.INDEX_TYPE.NOTUNIQUE, indexAttribute);
            db.getMetadata().getSchema().save();
        }
        catch(Exception e){
            e.printStackTrace();
        }
        finally{
            db.close();
        }
    }
}

我总是得到以下异常:

Exception in thread "main" java.util.ServiceConfigurationError: com.orientechnologies.orient.core.index.OIndexFactory: Provider com.orientechnologies.orient.core.index.hashindex.local.OHashIndexFactory could not be instantiated: java.lang.NoSuchFieldError: UNIQUE_HASH
    at java.util.ServiceLoader.fail(Unknown Source)
    at java.util.ServiceLoader.access$100(Unknown Source)
    at java.util.ServiceLoader$LazyIterator.next(Unknown Source)
    at java.util.ServiceLoader$1.next(Unknown Source)
    at com.orientechnologies.orient.core.index.OIndexes.getFactories(OIndexes.java:76)
    at com.orientechnologies.orient.core.index.OIndexes.getAllFactories(OIndexes.java:87)
    at com.orientechnologies.orient.core.index.OIndexes.createIndex(OIndexes.java:117)
    at com.orientechnologies.orient.core.index.OIndexManagerShared.createIndex(OIndexManagerShared.java:76)
    at com.orientechnologies.orient.core.index.OIndexManagerProxy.createIndex(OIndexManagerProxy.java:68)
    at com.orientechnologies.orient.core.metadata.schema.OClassImpl.createIndex(OClassImpl.java:1123)
    at com.orientechnologies.orient.core.metadata.schema.OClassImpl.createIndex(OClassImpl.java:1085)
    at com.orientechnologies.orient.core.metadata.schema.OClassImpl.createIndex(OClassImpl.java:1081)

有谁知道这个的解决方案。我还尝试关闭和打开数据库,在之前保存模式并使用不同的索引类型,但没有任何积极的结果。

第二个问题:是否有必要定义模式来索引集合中的列/属性,还是有其他方法?

4

0 回答 0