Tigraine
Daniel Hoelbling talks about .NET

Virtual member call in constructor and NHibernate

November 7th, 2008 . by Daniel Hölbling

As you may have noticed, I’ve been doing some NHibernate work lately and really had a great time with this absolutely amazing ORM. Especially now that Microsoft abandoned Linq to SQL I really feel good about having made the step towards NHibernate.

Yesterday was one of those tricky days when something breaks and you have no clue why.

I have a table called “Orders” and there are “OrderItems”.

image

By writing the tests upfront, I found out that I’d like to be able to just say Repository.Add(Order) instead of persisting the Order and afterwards looping through the OrderItems and persisting them too.

To achieve this I changed the mapping to something like this:

<set name="OrderItems" cascade="all">
  <key column="OrderId" />
  <one-to-many class="OrderItem"/>
</set>

The cascade=all statement is what I searched for initially. When the order gets persisted, all OrderItems in the collection get persisted too, and everything is well.

But, since my POCO object looks like this:

public class Order
{
    public virtual long Id { get; set; }
    public virtual ISet<OrderItem> OrderItems { get; set; }
}

I got NullReferenceException whenever I tried to access OrderItems on new Order objects. And I thought, hey.. kinda sucks newing up the collection in my business layer, why not init it in it’s constructor:

    public Order()
    {
        OrderItems = new HashedSet<OrderItem>();
    }

So I could just do Order.OrderItems.Add(OrderItem) without having to instantiate a HashedSet anywhere.

I got a bit cautious when Visual Studio underlined OrderItems and made the cryptic announcement: “Virtual member call in constructor”.

Totally unaware of what this means, I just went on and ran my tests.

Imagine my face when almost all my tests failed due to an omnious nHibernateException:

NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions

I didn’t figure this out until today, but it had to do with the “Virtual member call in constructor” warning. I discovered this post by Brad Abrams that explains the topic.

Looks like if you set the collection in the constructor of the POCO object NHibernate will break with the above Exception.

Solution to avoid this? Init the collection from calling-code instead of within the object.

What would have helped the issue would be to not have concrete POCO objects but rather use interfaces instead of virtual members (Read Fabio Maulo’s post entity-name in action: Entity Abstraction on that topic).


View Comments to “Virtual member call in constructor and NHibernate”

  1. comment number 1 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  2. comment number 2 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  3. comment number 3 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  4. comment number 4 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  5. comment number 5 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  6. comment number 6 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  7. comment number 7 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  8. comment number 8 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  9. comment number 9 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  10. comment number 10 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  11. comment number 11 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  12. comment number 12 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  13. comment number 13 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  14. comment number 14 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  15. comment number 15 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  16. comment number 16 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  17. comment number 17 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  18. comment number 18 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  19. comment number 19 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  20. comment number 20 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  21. comment number 21 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  22. comment number 22 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  23. comment number 23 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  24. comment number 24 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  25. comment number 25 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  26. comment number 26 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  27. comment number 27 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  28. comment number 28 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  29. comment number 29 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  30. comment number 30 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  31. comment number 31 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  32. comment number 32 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  33. comment number 33 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  34. comment number 34 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  35. comment number 35 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  36. comment number 36 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  37. comment number 37 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  38. comment number 38 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  39. comment number 39 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  40. comment number 40 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  41. comment number 41 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  42. comment number 42 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  43. comment number 43 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  44. comment number 44 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  45. comment number 45 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  46. comment number 46 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  47. comment number 47 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  48. comment number 48 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  49. comment number 49 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  50. comment number 50 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  51. comment number 51 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  52. comment number 52 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  53. comment number 53 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  54. comment number 54 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  55. comment number 55 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  56. comment number 56 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  57. comment number 57 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  58. comment number 58 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  59. comment number 59 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  60. comment number 60 by: Daniel Hu00f6lbling

    That didn’t work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..rnI also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.rnrnThanks anyway, I guess initializing the collection isn’t all that difficult after all :)

  61. comment number 61 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  62. comment number 62 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  63. comment number 63 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  64. comment number 64 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  65. comment number 65 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  66. comment number 66 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  67. comment number 67 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  68. comment number 68 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  69. comment number 69 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  70. comment number 70 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  71. comment number 71 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  72. comment number 72 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  73. comment number 73 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  74. comment number 74 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  75. comment number 75 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  76. comment number 76 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  77. comment number 77 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  78. comment number 78 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  79. comment number 79 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  80. comment number 80 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  81. comment number 81 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  82. comment number 82 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  83. comment number 83 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  84. comment number 84 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  85. comment number 85 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  86. comment number 86 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  87. comment number 87 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  88. comment number 88 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  89. comment number 89 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  90. comment number 90 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  91. comment number 91 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  92. comment number 92 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  93. comment number 93 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  94. comment number 94 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  95. comment number 95 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  96. comment number 96 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  97. comment number 97 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  98. comment number 98 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  99. comment number 99 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  100. comment number 100 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  101. comment number 101 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  102. comment number 102 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  103. comment number 103 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  104. comment number 104 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  105. comment number 105 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  106. comment number 106 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  107. comment number 107 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  108. comment number 108 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  109. comment number 109 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  110. comment number 110 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  111. comment number 111 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  112. comment number 112 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  113. comment number 113 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  114. comment number 114 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  115. comment number 115 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  116. comment number 116 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  117. comment number 117 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  118. comment number 118 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  119. comment number 119 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  120. comment number 120 by: Daniel Hu00f6lbling

    public virtual ISet OrderItemsrn {rn get { return orderItems_; }rn set { orderItems_ = value; }rn }rnrn private ISet orderItems_;rnrn public Order()rn {rn orderItems_ = new HashedSet();rn }rnrnI know it should work that way, but it doesn’t.rnCan’t say why. But it doesn’t work. rnrnMaybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.rnrnI think I’ll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

  121. comment number 121 by: Ayende Rahien

    The solution to this is init the collection via the property, but to initialize the field.

  122. comment number 122 by: Tigraine

    That didn't work.. I tried having a private field that gets accessed through the property and that gets set by the ctor..
    I also tried to set the field on demand from the property, but both times I got the “Illegal attempt to associate a collection with two open sessions”.

    Thanks anyway, I guess initializing the collection isn't all that difficult after all :)

  123. comment number 123 by: Ayende Rahien

    You set the field in the ctor, not touching the property, and that will work

  124. comment number 124 by: Tigraine

    public virtual ISet<OrderItem> OrderItems
    {
    get { return orderItems_; }
    set { orderItems_ = value; }
    }

    private ISet<OrderItem> orderItems_;

    public Order()
    {
    orderItems_ = new HashedSet<OrderItem>();
    }

    I know it should work that way, but it doesn't.
    Can't say why. But it doesn't work.

    Maybe I should have added that the problem is occuring during my Repository unit tests. If I run the tests one by one it works, but if they get executed all together I get the exception.

    I think I'll dedicate some more time to the problem tomorrow. But debugging concurrency issues sucks.

Leave a Reply

Name

Mail (never published)

Website

blog comments powered by Disqus