3

我们正在使用几个使用 NHibernate 的 Web 应用程序连接到 PostGIS 服务器。我们的日志文件充满了这个警告:

the custom type 'GeoAPI.Geometries.IGeometry' handled by 'NHibernate.Spatial.Type.GeometryType' is not Serializable

我用谷歌搜索过,看到很多其他人报告了同样的问题,但我没有找到任何解决方案。

我什至不确定这是 NHibernate 还是 GeoAPI 的问题。

任何帮助深表感谢。

4

1 回答 1

2

我可以向您展示导致此警告的一系列事件。

  1. PostGisDialect.cs - 这是 PostGIS 使用的方言。注意:

    public IGeometryUserType CreateGeometryUserType()
    {
        return new PostGisGeometryType();
    }
    
  2. PostGisGeometryType - 注意它实现了 GeometryTypeBase。

  3. 几何类型基础。注意:

    public System.Type ReturnedType
    {
        get { return typeof(IGeometry); }
    }
    
  4. GeometryType.cs - 现在这个用于处理几何列映射。注意:

    this.geometryUserType = SpatialDialect.LastInstantiated.CreateGeometryUserType();
    ...
    public System.Type ReturnedType
    {
        get { return this.geometryUserType.ReturnedType; }
    }
    
  5. 最后一块:CustomType

    if (!userType.ReturnedType.IsSerializable)
    {
        LoggerProvider.LoggerFor(typeof(CustomType)).WarnFormat("the custom type '{0}' handled by '{1}' is not Serializable: ", userType.ReturnedType, userTypeClass);
    }
    

所以 GeometryType.ReturnValue 应该是可序列化的以避免这个警告。GeometryType 使用 PostGisDialect,后者又使用 PostGisGeometryType,它继承自 GeometryTypeBase,它总是返回 IGeometry,因为它是 ReturnedType。当然接口不能是可序列化的,因此这个警告(它应该对实际上从 GeometryTypeBase 继承的任何几何类型产生相同的警告,如 Oracle 或 Sql Server)。实现 IGeometry 的实际类型实际上是可序列化的。

总结是什么?我认为这个检查在这种情况下只会返回误报。也许它应该检查 ReturnType 是否是接口,在这种情况下不产生警告。在这里使用接口是完全合法的。

关于这个实际上有一个未解决的问题:here,它已经有 2 年历史了,但他们没有深入挖掘以意识到它看起来的实际问题是什么。我会给他们发这个帖子的链接,也许他们会修复它。

于 2016-04-04T16:42:52.837 回答