7

我在我以前从未见过的日志中发现了这个异常,我使用的是 Hibernate 4.1.7

这是否表明我的数据库已损坏,或者这是 Hibernate 中的错误。我在http://lists.jboss.org/pipermail/hibernate-issues/2010-November/026487.html找到了对这个错误的引用,但这指的是更早版本的 hibernate 并且已针对 Hibernate 4.0 修复

org.hiorg.hibernate.HibernateException: IOException occurred reading a binary value
    at org.hibernate.type.descriptor.java.DataHelper.extractBytes(DataHelper.java:187)
    at org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor.wrap(PrimitiveByteArrayTypeDescriptor.java:124)
    at org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor.wrap(PrimitiveByteArrayTypeDescriptor.java:41)
    at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$5.doExtract(BlobTypeDescriptor.java:118)
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:65)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:269)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
    at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:357)
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2807)
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1545)
    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1477)
    at org.hibernate.loader.Loader.getRow(Loader.java:1377)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:644)
    at org.hibernate.loader.Loader.doQuery(Loader.java:854)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:293)
    at org.hibernate.loader.Loader.doList(Loader.java:2382)
    at org.hibernate.loader.Loader.doList(Loader.java:2368)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2198)
    at org.hibernate.loader.Loader.list(Loader.java:2193)
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:122)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1618)
    at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:374)
    at com.jthink.songkong.db.SongCache.loadSongsFromDatabase(SongCache.java:57)
    at com.jthink.songkong.analyse.analyser.SongGroup.getSongs(SongGroup.java:48)
    at com.jthink.songkong.analyse.analyser.DiscogsSongGroupMatcher.call(DiscogsSongGroupMatcher.java:63)
    at com.jthink.songkong.analyse.analyser.DiscogsSongGroupMatcher.call(DiscogsSongGroupMatcher.java:28)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.io.IOException: org.h2.jdbc.JdbcSQLException: IO Exception: "Missing lob entry: 5587/4" [90028-172]
    at org.h2.message.DbException.convertToIOException(DbException.java:348)
    at org.h2.store.LobStorageBackend$LobInputStream.fillBuffer(LobStorageBackend.java:695)
    at org.h2.store.LobStorageBackend$LobInputStream.readFully(LobStorageBackend.java:668)
    at org.h2.store.LobStorageBackend$LobInputStream.read(LobStorageBackend.java:654)
    at org.hibernate.type.descriptor.java.DataHelper.extractBytes(DataHelper.java:179)
    ... 31 more
Caused by: org.h2.jdbc.JdbcSQLException: IO Exception: "Missing lob entry: 5587/4" [90028-172]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
    at org.h2.message.DbException.get(DbException.java:169)
    at org.h2.message.DbException.get(DbException.java:146)
    at org.h2.store.LobStorageBackend.readBlock(LobStorageBackend.java:203)
    at org.h2.store.LobStorageBackend$LobInputStream.fillBuffer(LobStorageBackend.java:692)
    ... 34 more
4

3 回答 3

3

让我们从 Hibernate 的文档开始:

@Lob indicates that the property should be persisted in a Blob or a Clob depending on the property type: java.sql.Clob, Character[], char[] and java.lang.String will be persisted in a Clob. java.sql.Blob, Byte[], byte[] and serializable type will be persisted in a Blob.

例如:

@Lob
public String getFullText() {
    return fullText;
}

@Lob 
public byte[] getFullCode() {
    return fullCode;
}

知道这一点,这可能意味着该对象不在数据库中。也许它已从表中删除,但在引用的表中没有。假设从 table中删除Blobs了带有 5 的 blob id,但在 tableusers_blobs中仍然引用它,如下所示:

| user_id | blob_id|
|    4    |    5   | //This entry blob were delete but is still referenced by that table
|    5    |    2   | 

如果是这种情况,您应该重新定义users_blobs(例如)约束,以便在删除nullblob 时将其删除或放置。

此外,此链接也可能很有用:

http://h2-database.66688.n3.nabble.com/IO-Exception-quot-Missing-lob-entry-1-0-quot-90028-171-when-trying-to-read-a-BLOB-长于 128-bye-td4026236.html

于 2013-09-18T16:54:15.520 回答
1

似乎您正在尝试加载已删除的数据寄存器,请尝试同步访问该休眠 DAO。多线程应用程序应该每个线程使用一个连接。

于 2013-09-18T16:35:46.050 回答
1

这肯定是数据库的问题,而不是休眠的问题。您必须查看异常的原因h2,这是数据库代码中引发的异常。

Caused by: org.h2.jdbc.JdbcSQLException: IO Exception: "Missing lob entry: 5587/4" [90028-172]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
    at org.h2.message.DbException.get(DbException.java:169)
    at org.h2.message.DbException.get(DbException.java:146)
    at org.h2.store.LobStorageBackend.readBlock(LobStorageBackend.java:203)
    at org.h2.store.LobStorageBackend$LobInputStream.fillBuffer(LobStorageBackend.java:692)

在互联网上搜索“h2 database Missing lob entry”表明这是一条h2特定的错误消息,答案如下: https ://groups.google.com/forum/#!topic/h2-database/xey-czIhocM 表明它是很可能数据库已损坏。

如果这种情况更频繁地发生,更多关于这种情况如何发生的研究将是适当的。但这h2在数据库开发人员活跃的那个组中做得最好。

于 2013-09-18T08:48:38.033 回答