com.sleepycat.je.DatabaseNotFoundException 找不到数据库

发布于 2024-11-28 09:11:56 字数 2468 浏览 3 评论 0原文

我有数据库 /home/panayk/Desktop/panag_3/panag_3.tld:BerkeleyDB

$ db_verify /home/panayk/Desktop/panag_3/panag_3.tld 
Verification of /home/panayk/Desktop/panag_3/panag_3.tld succeeded.

拒绝打开它。

这是我的导入:

import com.sleepycat.bind.EntryBinding;
import com.sleepycat.bind.serial.SerialBinding;
import com.sleepycat.bind.serial.StoredClassCatalog;
import com.sleepycat.collections.StoredMap;
import com.sleepycat.collections.TransactionRunner;
import com.sleepycat.collections.TransactionWorker;
import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseConfig;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;

这是我的代码:

final File file = new File(filename);

final String homeDirectoryName = file.getParent();
final File homeDirectory = new File(homeDirectoryName);

LOGGER.info("Opening environment in {}.", homeDirectoryName);

final EnvironmentConfig environmentConfig = new EnvironmentConfig();
environmentConfig.setTransactional(true);
environmentConfig.setAllowCreate(true);

final DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(false);

environment = new Environment(homeDirectory, environmentConfig);

LOGGER.info("Opening database in {}.", filename);
database = environment.openDatabase(null, filename, dbConfig);

catalog = new StoredClassCatalog(database);

final EntryBinding keyBinding = new SerialBinding(catalog, Object.class);
final EntryBinding valueBinding = new SerialBinding(catalog, Object.class);

map = new StoredMap(database, keyBinding, valueBinding, true);

这是日志:

15:55:54,498  INFO TLDImporter:38 - Opening environment in /home/panayk/Desktop/panag_3.
15:55:54,779  INFO TLDImporter:50 - Opening database in /home/panayk/Desktop/panag_3/panag_3.tld.

这是例外:

com.sleepycat.je.DatabaseNotFoundException: (JE 4.1.10) Database /home/panayk/Desktop/panag_3/panag_3.tld not found.
    at com.sleepycat.je.Environment.setupDatabase(Environment.java:790)
    at com.sleepycat.je.Environment.openDatabase(Environment.java:536)
    at gr.panayk.vinyls.importer.TLDImporter.<init>(TLDImporter.java:51)
    at gr.panayk.vinyls.persistence.HibernateEntityRegistry.initialize(HibernateEntityRegistry.java:36)
    ... 60 more

出了什么问题?该文件显然存在。

I have the database /home/panayk/Desktop/panag_3/panag_3.tld:

$ db_verify /home/panayk/Desktop/panag_3/panag_3.tld 
Verification of /home/panayk/Desktop/panag_3/panag_3.tld succeeded.

BerkeleyDB refuses to open it.

Here are my imports:

import com.sleepycat.bind.EntryBinding;
import com.sleepycat.bind.serial.SerialBinding;
import com.sleepycat.bind.serial.StoredClassCatalog;
import com.sleepycat.collections.StoredMap;
import com.sleepycat.collections.TransactionRunner;
import com.sleepycat.collections.TransactionWorker;
import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseConfig;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;

And here is my code:

final File file = new File(filename);

final String homeDirectoryName = file.getParent();
final File homeDirectory = new File(homeDirectoryName);

LOGGER.info("Opening environment in {}.", homeDirectoryName);

final EnvironmentConfig environmentConfig = new EnvironmentConfig();
environmentConfig.setTransactional(true);
environmentConfig.setAllowCreate(true);

final DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(false);

environment = new Environment(homeDirectory, environmentConfig);

LOGGER.info("Opening database in {}.", filename);
database = environment.openDatabase(null, filename, dbConfig);

catalog = new StoredClassCatalog(database);

final EntryBinding keyBinding = new SerialBinding(catalog, Object.class);
final EntryBinding valueBinding = new SerialBinding(catalog, Object.class);

map = new StoredMap(database, keyBinding, valueBinding, true);

This is the log:

15:55:54,498  INFO TLDImporter:38 - Opening environment in /home/panayk/Desktop/panag_3.
15:55:54,779  INFO TLDImporter:50 - Opening database in /home/panayk/Desktop/panag_3/panag_3.tld.

And here is the exception:

com.sleepycat.je.DatabaseNotFoundException: (JE 4.1.10) Database /home/panayk/Desktop/panag_3/panag_3.tld not found.
    at com.sleepycat.je.Environment.setupDatabase(Environment.java:790)
    at com.sleepycat.je.Environment.openDatabase(Environment.java:536)
    at gr.panayk.vinyls.importer.TLDImporter.<init>(TLDImporter.java:51)
    at gr.panayk.vinyls.persistence.HibernateEntityRegistry.initialize(HibernateEntityRegistry.java:36)
    ... 60 more

What's wrong? The file obviously exists.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海拔太高太耀眼 2024-12-05 09:11:57

来自 http: //www.javasourcecode.org/html/open-source/berkeleydb/berkeleydb-4.1.6/com/sleepycat/je/Environment.java.html

/* No database. Create if we're allowed to. */
if (dbConfig.getAllowCreate()) {

    /*
     * We're going to have to do some writing. Switch to a
     * writable locker if we don't already have one.  Note
     * that the existing locker does not hold the handle lock
     * we need, since the database was not found; therefore it
     * is OK to call operationEnd on the existing locker.
     */
    if (!isWritableLocker) {
        locker.operationEnd(OperationStatus.SUCCESS);
        locker = LockerFactory.getWritableLocker
            (this,
             txn,
             dbConfig.getTransactional(),
             true,  // retainNonTxnLocks
             autoTxnIsReplicated,
             null);
        isWritableLocker  = true;
    }

    newDb.initNew(this, locker, databaseName, dbConfig);
} else {
    /* We aren't allowed to create this database. */
    throw new DatabaseNotFoundException("Database " +
                                        databaseName +
                                        " not found.");
}

而你已设置

final DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(false);

setAllowCreate 为 false。通过查看代码,这似乎是问题所在。

From http://www.javasourcecode.org/html/open-source/berkeleydb/berkeleydb-4.1.6/com/sleepycat/je/Environment.java.html

/* No database. Create if we're allowed to. */
if (dbConfig.getAllowCreate()) {

    /*
     * We're going to have to do some writing. Switch to a
     * writable locker if we don't already have one.  Note
     * that the existing locker does not hold the handle lock
     * we need, since the database was not found; therefore it
     * is OK to call operationEnd on the existing locker.
     */
    if (!isWritableLocker) {
        locker.operationEnd(OperationStatus.SUCCESS);
        locker = LockerFactory.getWritableLocker
            (this,
             txn,
             dbConfig.getTransactional(),
             true,  // retainNonTxnLocks
             autoTxnIsReplicated,
             null);
        isWritableLocker  = true;
    }

    newDb.initNew(this, locker, databaseName, dbConfig);
} else {
    /* We aren't allowed to create this database. */
    throw new DatabaseNotFoundException("Database " +
                                        databaseName +
                                        " not found.");
}

And you have set

final DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(false);

The setAllowCreate is false. That appears to be the issue by looking at the code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文