Orientdb 返回对象的属性访问引发ODatabaseException:当前线程中未设置数据库

Orientdb 返回对象的属性访问引发ODatabaseException:当前线程中未设置数据库,orientdb,Orientdb,我正在使用orientdb-object-2.1.9并尝试设置一个基本存储库来保存和查找对象 但是当从数据库访问返回对象的任何属性时,它抛出一个ODatabaseException,该数据库未在当前线程中设置 下面是一个失败的测试,显示了我对API的使用情况 import javax.persistence.Id; import javax.persistence.Version; import com.orientechnologies.orient.core.db.OPartitioned

我正在使用orientdb-object-2.1.9并尝试设置一个基本存储库来保存和查找对象

但是当从数据库访问返回对象的任何属性时,它抛出一个ODatabaseException,该数据库未在当前线程中设置

下面是一个失败的测试,显示了我对API的使用情况

import javax.persistence.Id;
import javax.persistence.Version;

import com.orientechnologies.orient.core.db.OPartitionedDatabasePool;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class ObjectDatabaseTest {
private MyObjectAuthorRepository repository;

@Before
public void setUp() {
    repository = new MyObjectAuthorRepository();
}

@After
public void tearDown() {
    repository.close();
}

@Test
public void testAuthor() {
    Author savedAuthor = repository.saveAuthor(new Author("Author Name"));
    // a detached object also fails when accessing the property
    // Assert.assertEquals("Author Name", savedAuthor.getAuthorName());
    Author author = repository.findAuthor();
    Assert.assertEquals("Author Name", author.getAuthorName());
}

class MyObjectAuthorRepository {
    private final OPartitionedDatabasePool pool;

    public MyObjectAuthorRepository() {
        pool = new OPartitionedDatabasePool("memory:test", "admin", "admin");
        pool.setAutoCreate(true);
        try (OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
            db.setAutomaticSchemaGeneration(true);
            db.getEntityManager().registerEntityClass(Author.class);
        }
    }

    private Author saveAuthor(Author author) {
        OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire());
        try {
            db.begin();
            Author savedAuthor = db.save(author);
            db.commit();
            return db.detach(savedAuthor);
        } catch (Exception ex) {
            db.rollback();
            throw ex;
        } finally {
            db.close();
        }
    }

    public Author findAuthor() {
        try (OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
            return db.browseClass(Author.class).next();
        }
    }

    public void close() {
        pool.close();
    }
}

@javax.persistence.Entity
public class Author {
    @Id
    private String id;
    @Version
    private Long version;
    private String authorName;

    public Author() {
    }

    public Author(String authorName) {
        this.authorName = authorName;
    }

    public String getId() {
        return id;
    }

    public Long getVersion() {
        return version;
    }

    public String getAuthorName() {
        return authorName;
    }

    public void setAuthorName(String authorName) {
        this.authorName = authorName;
    }
}
}
请让我知道,如果API应该以不同的方式使用,或者如果我在上面缺少任何其他配置。这真的很有帮助。谢谢