0

我有一个类 Document ,它由Id (int)和组成Url (String)。我想有一个主索引Id和二级索引Url。我还想有一个 Id 自动递增的序列。所以我创建了一个 SecondaryDatabase,然后我创建了一个序列。在序列初始化期间,我得到一个异常:

Exception in thread "main" java.lang.IllegalArgumentException
 at com.sleepycat.util.UtfOps.getCharLength(UtfOps.java:137)
 at com.sleepycat.util.UtfOps.bytesToString(UtfOps.java:259)
 at com.sleepycat.bind.tuple.TupleInput.readString(TupleInput.java:152)
 at pl.edu.mimuw.zbd.berkeley.zadanie.rozwiazanie.MyDocumentBiding.entryToObject(MyDocumentBiding.java:12)
 at pl.edu.mimuw.zbd.berkeley.zadanie.rozwiazanie.MyDocumentBiding.entryToObject(MyDocumentBiding.java:1)
 at com.sleepycat.bind.tuple.TupleBinding.entryToObject(TupleBinding.java:76)
 at pl.edu.mimuw.zbd.berkeley.zadanie.rozwiazanie.UrlKeyCreator.createSecondaryKey(UrlKeyCreator.java:20)
 at com.sleepycat.je.SecondaryDatabase.updateSecondary(SecondaryDatabase.java:835)
 at com.sleepycat.je.SecondaryTrigger.databaseUpdated(SecondaryTrigger.java:42)
 at com.sleepycat.je.Database.notifyTriggers(Database.java:2004)
 at com.sleepycat.je.Cursor.putNotify(Cursor.java:1692)
 at com.sleepycat.je.Cursor.putInternal(Cursor.java:1616)
 at com.sleepycat.je.Cursor.putNoOverwrite(Cursor.java:663)
 at com.sleepycat.je.Sequence.<init>(Sequence.java:188)
 at com.sleepycat.je.Database.openSequence(Database.java:546)
 at pl.edu.mimuw.zbd.berkeley.zadanie.rozwiazanie.MyFullTextSearchEngine.init(MyFullTextSearchEngine.java:131)
 at pl.edu.mimuw.zbd.berkeley.zadanie.testy.MyFullTextSearchEngineTest.main(MyFullTextSearchEngineTest.java:18)

似乎在序列初始化期间,辅助数据库被迫更新。当我调试 MyDocumentBiding 的 entryToObject 方法时,它尝试转换为对象的字节似乎是随机的。

我究竟做错了什么?

4

1 回答 1

0

我发现解决方案是为序列创建一个单独的数据库,或者让 SecondaryKeyCreator 检测它何时添加序列数据并在这种情况下返回 false。

于 2010-01-16T23:19:14.947 回答