gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:04:41 26 4
gpt4 key购买 nike

编辑:解决方案: 升级到 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 字段内容Document类:

@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 类 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 框架的类 org.apache.isis.objectstore.jdo.datanucleus.valuetypes.IsisBlobMapping 应该执行映射。但这个Mapper似乎并没有参与其中......

<强>1。问题:如何将 Blob 字段分成三列(如上所述和许多演示项目中所述)。即使我切换到 HSQLDB,我仍然只获得一列,因此这可能不是 MariaDB 的问题。

<强>2。问题:如果我在从另一个 DomainObject 类继承的类中使用 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$1.loadInBulk(EntityCollectionModel.java:107)
at org.apache.isis.viewer.wicket.model.models.EntityCollectionModel$Type$1.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$1#loadInBulk(EntityCollectionModel.java:107)
at org.apache.isis.viewer.wicket.model.models.EntityCollectionModel$Type$1#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$1#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 bug 报告,这个问题在 1.17.0 中得到了修复,所以我正在尝试从 1.16.2 升级到这个版本(这引入了许多其他问题,但这将是一个额外的话题)。

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

更新:

  1. 我将项目升级到 ISIS 版本 1.17.0。它解决了我在问题 1 中的问题(现在我得到了 Blob/Clob 对象的三列)。
  2. 问题 2 中的问题 (NucleusException) 并未通过升级得到解决。我发现只有返回带有 Blob/Clob 字段的 DomainObjects 列表(即呈现为独立表)时才会抛出该错误。如果我直接进入对象的实体 View ,则不会引发异常,并且我可以查看/修改/下载 Blob/Clob 内容。
  3. 与此同时,我编写了自己的 datanucleus 插件,它将 Blob/Clob 作为文件存储在文件系统上。

更新2

  • 我找到了一个解决方案来规避org.datanucleus.exceptions.NucleusException:无法创建 SQLExpression 来映射类型“org.apache.isis.objectstore.jdo.datanucleus.valuetypes” .IsisClobMapping”,因为不支持。这似乎是批量加载的问题(但我不知道任何细节)。通过属性 isis.persistor.datanucleus.standaloneCollection.bulkLoad=false(最初由 ISIS 原型(prototype)设置为 true)停用批量加载解决了问题。
  • 关于java - ISIS:Blob/Clob 字段序列化问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55400554/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com