我已经很久没有使用 envers 了,我遇到了一个问题,我似乎无法在任何地方找到答案。我试过谷歌搜索堆栈跟踪但无济于事,所以我一定错过了一些非常明显的东西。每当我尝试在 org.hibernate.envers.AuditReader 中运行“find(class, versionNumber)”方法以检索数据库中文档类的先前版本时,我似乎都会得到以下堆栈跟踪:
java.lang.NullPointerException
org.hibernate.envers.entities.EntityInstantiator.createInstanceFromVersionsEntity(EntityInstantiator.java:91)
org.hibernate.envers.entities.EntityInstantiator.addInstancesFromVersionsEntities(EntityInstantiator.java:113)
org.hibernate.envers.query.impl.EntitiesAtRevisionQuery.list(EntitiesAtRevisionQuery.java:110)
org.hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:108)
org.hibernate.envers.reader.AuditReaderImpl.find(AuditReaderImpl.java:119)
org.hibernate.envers.reader.AuditReaderImpl.find(AuditReaderImpl.java:94)
com.example.repository.AbstractDocumentTypeManager.getVersion(AbstractDocumentTypeManager.java:221)
com.example.repository.AbstractDocumentTypeManager.getVersion(AbstractDocumentTypeManager.java:1)
com.example.logic.versioning.BaseVersioningService.getApprovedSnapshot(BaseVersioningService.java:54)
com.example.logic.versioning.BaseVersioningService$$FastClassByCGLIB$$d33887d.invoke(<generated>)
net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
...
导致此错误的代码如下。它发生在我的文档被保存之后,并且似乎正在数据库中创建适当的版本(document_AUD)。
public Document getVersion(String objectId, Number version) {
AuditReader auditReader = getAuditReader();
/* at this point, i guarantee that neither objectId nor version are null. */
Document revision = auditReader.find(Document.class, objectId, version);
return revision;
}
public AuditReader getAuditReader() {
return AuditReaderFactory.get(entityManager);
}
我的“文档”类是这样注释的......
@Entity(name = "document")
@DiscriminatorColumn(name = "DTYPE", discriminatorType = DiscriminatorType.STRING)
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@Cacheable(true)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "modelObjectCache")
public abstract class Document<T extends Document<?>> extends ModelObject implements Serializable, Comparable<T>,
Versionable {
/* many properties of a Document here. There are 2 subclasses of Document, identified by a database discriminator. */
}
请让我知道您需要更多代码才能正确找到此问题。
非常感谢您的阅读,欢迎提出任何建议,
富有的。