简体   繁体   English

随着NHibernate 4的升级而破坏变化

[英]Breaking changes with NHibernate 4 upgrade

I can see what's new and fixed in NHibernate 4.0 我可以在NHibernate 4.0中看到新的和修复的内容

I would like to know if anyone has had issue with hbm mappings upgrading from NHibernate 3 to 4? 我想知道是否有人遇到从NHibernate 3升级到4的hbm映射问题?

I fear that more focus is going on fluent mapping these days. 我担心这些日子会更加注重流畅的绘图。 I can test for the more obvious breaking changes but wanted to know if there were any subtle issues that anyone has come across in a production environment that may not be so obvious at first. 我可以测试更明显的重大变化,但想知道是否有任何人在生产环境中遇到的任何细微问题,一开始可能不那么明显。

It looks like a major upgrade and you'd expect there to be the risk of regressions. 它看起来像是一次重大升级,你可能会有回归的风险。

FYI, I found a new error that is thrown. 仅供参考,我发现了一个新错误。 We use Mapping By Code, and we used to have an entity that had multiple Bag mappings with the Fetch type set to Join with NHibernate v 3.3.x. 我们使用Mapping By Code,我们曾经有一个具有多个Bag映射的实体,其Fetch类型设置为Join with NHibernate v 3.3.x. This is no longer allowed in version 4.0.x. 版本4.0.x中不再允许这样做。

We received an error message of Cannot simultaneously fetch multiple bags. 我们收到一条错误消息, Cannot simultaneously fetch multiple bags. , which makes sense with what is necessary behind the scenes but it should technically be considered a breaking change. 这对幕后的必要条件有意义,但在技术上应该被认为是一个突破性的变化。 NHibernate was not nice enough to tell us which mapping was causing the issue. NHibernate还不足以告诉我们哪个映射导致了这个问题。

We were experiencing the same issue with a rather large QueryOver - Cannot simultaneously fetch multiple bags , with Nhibernate 4 and FluentNhibernate mappings. 我们遇到了一个相当大的QueryOver - Cannot simultaneously fetch multiple bags ,使用Nhibernate 4和FluentNhibernate映射。

The solution was to, on our FluentMaps, to set AsSet() (according to our backing fields) which in the end solved the issue. 解决方案是在我们的FluentMaps上设置AsSet() (根据我们的支持字段),这最终解决了问题。

As per request in the comment, here is a small sample of our mappings before and after the exception: 根据评论中的请求,以下是异常之前和之后的一小部分映射示例:

This is a very simplified showcase of our classes which caused the Cannot simultaneously fetch multiple bags . 这是我们课程的一个非常简化的展示,导致Cannot simultaneously fetch multiple bags The abstract Entity class belongs to the S#Arp lite architecture . 抽象Entity属于S#Arp lite体系结构 Before the changes it looked something like this 在改变之前它看起来像这样

public class OrderHeader : Entity
{
    public virtual IList<OrderItem> Items { get; set; }
}

public class OrderItem : Entity
{
    public virtual decimal Price {get; set;}
    public virtual string ItemNumber {get; set;}
    public virtual OrderHeader Header {get; set;}
}

public class OrderHeaderMap : ClassMap<OrderHeader>
{
    Id( e => e.Id).GeneratedBy.Native();
    HasMany(e => e.OrderItems).Inverse();
}

public class OrderItemMap : ClassMap<OrderItem>
{
    Id(e => e.Id).GeneratedBy.Native();
    References(e => e.Header).Not.Nullable();
}

As you can see the OrderHeader has an IList of items. 如您所见,OrderHeader具有IList项。 Changing this to 将此更改为

public class OrderHeader : Entity
{
    public virtual ISet<OrderItem> Items { get; set; } // ISet here
}

public class OrderItem : Entity
{
    public virtual decimal Price {get; set;}
    public virtual string ItemNumber {get; set;}
    public virtual OrderHeader Header {get; set;}
}

public class OrderHeaderMap : ClassMap<OrderHeader>
{
    Id( e => e.Id).GeneratedBy.Native();
    HasMany(e => e.OrderItems).Inverse();
}

public class OrderItemMap : ClassMap<OrderItem>
{
    Id(e => e.Id).GeneratedBy.Native();
    References(e => e.Header).Not.Nullable().AsSet(); // Explicit AsSet
}

So an ISet and the explicit AsSet() on the mapping made the issue go away. 因此, ISet和映射上的显式AsSet()使问题消失了。 This code snippet is very simplified and we had multiple entities in the QueryOver with HasMany() IList - when all were updated to the ISet , it worked properly. 这个代码片段非常简单,我们在QueryOver有多个实体和HasMany() IList - 当所有实体都更新到ISet ,它运行正常。

I wouldn't worry too much about the hbm itself. 我不会太担心hbm本身。 FluentNHibernate "compiles" to XML which goes through the mapping layer. FluentNHibernate“编译”到通过映射层的XML。 NHibernate's own mapping-by-code also uses parts of the same code as hbm files. NHibernate自己的代码映射也使用与hbm文件相同代码的部分。

Anyway, the mapping code hasn't changed very much. 无论如何,映射代码没有太大变化。 Any regressions are more likely to be in other parts. 任何回归都更可能出现在其他部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM