ISIS:Blob/Clob 字段序列化问题

ISIS: Problems with Blob/Clob field serialization

编辑:解决方案: 升级到 ISIS 1.17.0 并设置 属性 isis.persistor.datanucleus.standaloneCollection.bulkLoad=false 解决了前两个问题。


我正在使用 Apache ISIS 1.16.2,我尝试将 Blob/Clob 内容存储在 MariaDB 数据库 (v10.1.35) 中。因此,我使用数据库连接器 org.mariadb.jdbc.mariadb-java-client (v2.3.0) 并在代码中使用 @Persistent 注释,如许多示例和 ISIS 文档中所示。

使用下面的代码,我只得到一个名为 content_name 的列(其中 Blob 对象以二进制形式序列化)而不是三个列 content_namecontent_mimetypecontent_bytes.

这是带有 Blob 字段 content:

Document class
@PersistenceCapable(identityType = IdentityType.DATASTORE)
@DatastoreIdentity(strategy = IdGeneratorStrategy.IDENTITY, column = "id")
@DomainObject(editing = Editing.DISABLED, autoCompleteRepository = DocumentRepository.class, objectType = "Document")
@Getter
// ...
public class Document implements Comparable<Document> {

    @Persistent(
        defaultFetchGroup = "false",
        columns = {
            @Column(name = "content_name"),
            @Column(name = "content_mimetype"),
            @Column(name = "content_bytes",
                jdbcType = "BLOB",
                sqlType = "LONGVARBINARY")
            })
    @Nonnull
    @Column(allowsNull = "false")
    @Property(optionality = Optionality.MANDATORY)
    private Blob content;

    // ...

    @Column(allowsNull = "false")
    @Property
    private Date created = new Date();

    public Date defaultCreated() {
        return new Date();
    }

    @Column(allowsNull = "true")
    @Property
    @Setter
    private String owner;

    // ...
}

这为 DomainObject class Document 创建了以下模式,只有一列用于 Blob 字段:

CREATE TABLE `document` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `content_name` mediumblob,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `owner` varchar(255) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

正常情况下,ISIS框架的class org.apache.isis.objectstore.jdo.datanucleus.valuetypes.IsisBlobMapping应该做映射。但似乎这个Mapper不知何故没有参与...

1.问题: 如何将 Blob 字段拆分为三列(如上文和许多演示项目中所述)。即使我切换到 HSQLDB,我仍然只有一列,所以这可能不是 MariaDB 的问题。

2。问题: 如果我在从另一个 DomainObject class 继承的 class 中使用 Blob/Clob 字段,我经常得到 org.datanucleus.exceptions.NucleusException (堆栈跟踪见下文)我不知道它的头尾。处理继承时有哪些潜在陷阱?为什么我会收到此异常?

3。问题: 我需要存储属于域对象的文档(您可能已经猜到了)。这样做的正确方法是将文档存储在文件系统树中而不是数据库中(默认情况下,数据库对对象数据也有一些大小限制)并引用对象中的文件。在 Datanucleus documentation 中,我发现扩展 serializeToFileLocation 应该可以做到这一点。我尝试将行 @Extension(vendorName="datanucleus", key="serializeToFileLocation" value="document-repository") 添加到 Blob 字段,但没有任何反应。所以我的问题是:这个 Datanucleus 扩展是否与 Apache Isis 兼容?

如果此扩展与 Isis 冲突,是否可以使用 javax.jdo.listener.StoreLifecycleListenerorg.apache.isis.applib.AbstractSubscriber 将 Blob 存储在文件系统上,然后将域对象持久保存到数据库并在加载之前恢复它?有更好的解决方案吗?

到此为止。先感谢您! ;-)


问题 2 的堆栈跟踪:

... (other Wicket related stack trace)
Caused by: org.datanucleus.exceptions.NucleusException: Creation of SQLExpression for mapping "org.datanucleus.store.rdbms.mapping.java.SerialisedMapping" caused error
        at org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory.newExpression(SQLExpressionFactory.java:199)
        at org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory.newExpression(SQLExpressionFactory.java:155)
        at org.datanucleus.store.rdbms.request.LocateBulkRequest.getStatement(LocateBulkRequest.java:158)
        at org.datanucleus.store.rdbms.request.LocateBulkRequest.execute(LocateBulkRequest.java:283)
        at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.locateObjects(RDBMSPersistenceHandler.java:564)
        at org.datanucleus.ExecutionContextImpl.findObjects(ExecutionContextImpl.java:3313)
        at org.datanucleus.api.jdo.JDOPersistenceManager.getObjectsById(JDOPersistenceManager.java:1850)
        at org.apache.isis.core.runtime.system.persistence.PersistenceSession.loadPersistentPojos(PersistenceSession.java:1010)
        at org.apache.isis.core.runtime.system.persistence.PersistenceSession.adaptersFor(PersistenceSession.java:1603)
        at org.apache.isis.core.runtime.system.persistence.PersistenceSession.adaptersFor(PersistenceSession.java:1573)
        at org.apache.isis.viewer.wicket.model.models.EntityCollectionModel$Type.loadInBulk(EntityCollectionModel.java:107)
        at org.apache.isis.viewer.wicket.model.models.EntityCollectionModel$Type.load(EntityCollectionModel.java:93)
        at org.apache.isis.viewer.wicket.model.models.EntityCollectionModel.load(EntityCollectionModel.java:454)
        at org.apache.isis.viewer.wicket.model.models.EntityCollectionModel.load(EntityCollectionModel.java:70)
        at org.apache.wicket.model.LoadableDetachableModel.getObject(LoadableDetachableModel.java:135)
        at org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable.CollectionContentsSortableDataProvider.size(CollectionContentsSortableDataProvider.java:68)
        at org.apache.wicket.markup.repeater.data.DataViewBase.internalGetItemCount(DataViewBase.java:142)
        at org.apache.wicket.markup.repeater.AbstractPageableView.getItemCount(AbstractPageableView.java:235)
        at org.apache.wicket.markup.repeater.AbstractPageableView.getRowCount(AbstractPageableView.java:216)
        at org.apache.wicket.markup.repeater.AbstractPageableView.getViewSize(AbstractPageableView.java:314)
        at org.apache.wicket.markup.repeater.AbstractPageableView.getItemModels(AbstractPageableView.java:99)
        at org.apache.wicket.markup.repeater.RefreshingView.onPopulate(RefreshingView.java:93)
        at org.apache.wicket.markup.repeater.AbstractRepeater.onBeforeRender(AbstractRepeater.java:124)
        at org.apache.wicket.markup.repeater.AbstractPageableView.onBeforeRender(AbstractPageableView.java:115)
        at org.apache.wicket.Component.internalBeforeRender(Component.java:950)
        at org.apache.wicket.Component.beforeRender(Component.java:1018)
        at org.apache.wicket.MarkupContainer.onBeforeRenderChildren(MarkupContainer.java:1825)
        ... 81 more
 Caused by: org.datanucleus.exceptions.NucleusException: Unable to create SQLExpression for mapping of type "org.datanucleus.store.rdbms.mapping.java.SerialisedMapping" since not supported
        at org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory#newExpression(SQLExpressionFactory.java:189)
        at org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory#newExpression(SQLExpressionFactory.java:155)
        at org.datanucleus.store.rdbms.request.LocateBulkRequest#getStatement(LocateBulkRequest.java:158)
        at org.datanucleus.store.rdbms.request.LocateBulkRequest#execute(LocateBulkRequest.java:283)
        at org.datanucleus.store.rdbms.RDBMSPersistenceHandler#locateObjects(RDBMSPersistenceHandler.java:564)
        at org.datanucleus.ExecutionContextImpl#findObjects(ExecutionContextImpl.java:3313)
        at org.datanucleus.api.jdo.JDOPersistenceManager#getObjectsById(JDOPersistenceManager.java:1850)
        at org.apache.isis.core.runtime.system.persistence.PersistenceSession#loadPersistentPojos(PersistenceSession.java:1010)
        at org.apache.isis.core.runtime.system.persistence.PersistenceSession#adaptersFor(PersistenceSession.java:1603)
        at org.apache.isis.core.runtime.system.persistence.PersistenceSession#adaptersFor(PersistenceSession.java:1573)
        at org.apache.isis.viewer.wicket.model.models.EntityCollectionModel$Type#loadInBulk(EntityCollectionModel.java:107)
        at org.apache.isis.viewer.wicket.model.models.EntityCollectionModel$Type#load(EntityCollectionModel.java:93)
        at org.apache.isis.viewer.wicket.model.models.EntityCollectionModel#load(EntityCollectionModel.java:454)
        at org.apache.isis.viewer.wicket.model.models.EntityCollectionModel#load(EntityCollectionModel.java:70)
        at org.apache.wicket.model.LoadableDetachableModel#getObject(LoadableDetachableModel.java:135)
        at org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable.CollectionContentsSortableDataProvider#size(CollectionContentsSortableDataProvider.java:68)
        at org.apache.wicket.markup.repeater.data.DataViewBase#internalGetItemCount(DataViewBase.java:142)
        at org.apache.wicket.markup.repeater.AbstractPageableView#getItemCount(AbstractPageableView.java:235)
        at org.apache.wicket.markup.repeater.AbstractPageableView#getRowCount(AbstractPageableView.java:216)
        at org.apache.wicket.markup.repeater.AbstractPageableView#getViewSize(AbstractPageableView.java:314)
        at org.apache.wicket.markup.repeater.AbstractPageableView#getItemModels(AbstractPageableView.java:99)
        at org.apache.wicket.markup.repeater.RefreshingView#onPopulate(RefreshingView.java:93)
        at org.apache.wicket.markup.repeater.AbstractRepeater#onBeforeRender(AbstractRepeater.java:124)
        at org.apache.wicket.markup.repeater.AbstractPageableView#onBeforeRender(AbstractPageableView.java:115)
        // <-- 8 times the following lines
        at org.apache.wicket.Component#internalBeforeRender(Component.java:950)
        at org.apache.wicket.Component#beforeRender(Component.java:1018)
        at org.apache.wicket.MarkupContainer#onBeforeRenderChildren(MarkupContainer.java:1825)
        at org.apache.wicket.Component#onBeforeRender(Component.java:3916)
        // -->
        at org.apache.wicket.Page#onBeforeRender(Page.java:801)
        at org.apache.wicket.Component#internalBeforeRender(Component.java:950)
        at org.apache.wicket.Component#beforeRender(Component.java:1018)
        at org.apache.wicket.Component#internalPrepareForRender(Component.java:2236)
        at org.apache.wicket.Page#internalPrepareForRender(Page.java:242)
        at org.apache.wicket.Component#render(Component.java:2325)
        at org.apache.wicket.Page#renderPage(Page.java:1018)
        at org.apache.wicket.request.handler.render.WebPageRenderer#renderPage(WebPageRenderer.java:124)
        at org.apache.wicket.request.handler.render.WebPageRenderer#respond(WebPageRenderer.java:195)
        at org.apache.wicket.core.request.handler.RenderPageRequestHandler#respond(RenderPageRequestHandler.java:175)
        at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor#respond(RequestCycle.java:895)
        at org.apache.wicket.request.RequestHandlerStack#execute(RequestHandlerStack.java:64)
        at org.apache.wicket.request.cycle.RequestCycle#execute(RequestCycle.java:265)
        at org.apache.wicket.request.cycle.RequestCycle#processRequest(RequestCycle.java:222)
        at org.apache.wicket.request.cycle.RequestCycle#processRequestAndDetach(RequestCycle.java:293)
        at org.apache.wicket.protocol.http.WicketFilter#processRequestCycle(WicketFilter.java:261)
        at org.apache.wicket.protocol.http.WicketFilter#processRequest(WicketFilter.java:203)
        at org.apache.wicket.protocol.http.WicketFilter#doFilter(WicketFilter.java:284)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain#doFilter(ServletHandler.java:1668)
        at org.apache.isis.core.webapp.diagnostics.IsisLogOnExceptionFilter#doFilter(IsisLogOnExceptionFilter.java:52)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain#doFilter(ServletHandler.java:1668)
        at org.apache.shiro.web.servlet.AbstractShiroFilter#executeChain(AbstractShiroFilter.java:449)
        at org.apache.shiro.web.servlet.AbstractShiroFilter#call(AbstractShiroFilter.java:365)
        at org.apache.shiro.subject.support.SubjectCallable#doCall(SubjectCallable.java:90)
        at org.apache.shiro.subject.support.SubjectCallable#call(SubjectCallable.java:83)
        at org.apache.shiro.subject.support.DelegatingSubject#execute(DelegatingSubject.java:383)
        at org.apache.shiro.web.servlet.AbstractShiroFilter#doFilterInternal(AbstractShiroFilter.java:362)
        at org.apache.shiro.web.servlet.OncePerRequestFilter#doFilter(OncePerRequestFilter.java:125)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain#doFilter(ServletHandler.java:1668)
        // ... some Jetty stuff
        at java.lang.Thread#run(Thread.java:748)

经过一番研究,我认为问题1和问题2的问题似乎与this ISIS bug report #1902有关。

简而言之:datanucleus 扩展插件解析机制似乎没有找到 ISIS 值类型适配器,因此不知道如何序列化 ISIS 的 Blob/Clob 类型。

根据前面提到的 ISIS 错误报告,这个问题在 1.17.0 中已经修复,所以我正在尝试从 1.16.2 升级到这个版本(这引入了许多其他问题,但这将是一个额外的主题) .

对于问题 3,我发现 Minio 基本上解决了我的问题,但对我的需求来说有点过大了。我会继续寻找其他解决方案来将 Blob/Clobs 存储到本地文件系统,并将记住 Minio...

更新

  1. 我将我的项目升级到 ISIS 1.17.0 版。它解决了我在问题 1 中的问题(现在我得到了一个 Blob/Clob 对象的三列)。
  2. 问题2(NucleusException)的问题升级后没有解决。我发现只有在返回具有 Blob/Clob 字段的 DomainObjects 列表时才会抛出它,即如果呈现为独立 table。如果我直接进入一个对象的实体视图,不会抛出异常,我可以 see/modify/download Blob/Clob 内容。
  3. 与此同时,我编写了自己的 datanucleus 插件,将 Blobs/Clobs 作为文件存储在文件系统上。

更新 2

  1. 我找到了绕过 org.datanucleus.exceptions.NucleusException: Unable to create SQLExpression for mapping of type "org.apache.isis.objectstore.jdo.datanucleus.valuetypes.IsisClobMapping" since not supported 解决方案 。这似乎是批量加载的问题(但我不知道任何细节)。 通过 属性 isis.persistor.datanucleus.standaloneCollection.bulkLoad=false(ISIS 原型最初设置为 true)停用批量加载解决了问题。