-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Add entity to a collection problem (entity not saved)
PostPosted: Tue Jul 29, 2008 4:21 am 
Newbie

Joined: Fri Jul 25, 2008 6:28 am
Posts: 3
Hi all,

I have a very unpleasant problem.


I have an entity named PhysicalStock which has a child collection of FinalOut entities.

Physical
- FinalOut1
- FinalOut2
- ....
- FinalOutN



PhysicalStock is a subclass of another entity named : StockBase,
but i will show you only the mapping for PhysicalStock.

Just for the record FinalOut also derives from StockBase.

Both FinalOut and PhysicalStock and all other derived classes from StockBase are HELD in a table named : NS_STOCK.

Therefore in order to get just the FinalOuts in the BAG, we put a WHERE clause in the HBM.


Here is the HBM mapping:

<subclass name="LogSys.LGS.BusinessObjects.Stock.PhysicalStock, LogSys.LGS.BusinessObjects" discriminator-value="2">
<bag name="FinalOuts" table="NS_STOCK" cascade="save-update" access="nosetter.camelcase"
lazy="true"
inverse="true"
where="STOCK_TYPE=7">
<key column="PHYSICAL_ID" />
<one-to-many class="LogSys.LGS.BusinessObjects.Stock.FinalOut, LogSys.LGS.BusinessObjects"/>
</bag>
</subclass>

So everything is quite classical. If yoy CREATE a new FinalOut and add it to the BAG, the it will be saved at SESSION COMMIT along with the Physical stock.

So for adding a final-out to the BAG, there is the following C# method in the PhysicalStock class:

class PhysicalStock : StockBase
{
...
...
/// <summary>
/// Adds a final-out fragment.
/// </summary>
/// <param name="finalOut">A FinalOut object.</param>
public virtual void AddFinalOut(
FinalOut finalOut)
{
finalOut.Physical = this;
FinalOuts.Add(finalOut);
}
...
...
}

Everything again is classical, but here goes the problem. If you run this method in DEBUG STEP-BY-STEP mode, all final-outs are correctly added to the BAG, and the SAVED at session commit.

BUT if you run it in RELEASE MODE, then sometimes, some final-outs are not saved (which is extremely strange thing).

What excited us most is :

if we change the method to the following:

class PhysicalStock : StockBase
{
...
...
/// <summary>
/// Adds a final-out fragment.
/// </summary>
/// <param name="finalOut">A FinalOut object.</param>
public virtual void AddFinalOut(
FinalOut finalOut)
{
finalOut.Physical = this;
FinalOuts.Add(finalOut);

// This is a WORKAROUND.
int count = FinalOuts.Count;

}
...
...
}

Then it works also in release mode.
(We use nHibernate.dll version 1.2.1.4000, but we tried with older versions and we get the same problem again)

Q: Can somebody explain to me why I need to add this workaround, so that I'm sure my Final-Out is in the BAG? I smell this is some kind of nHibernate bug, because there is no logical explanation for me, that I need to QUERY the COUNT of the BAG, so that elements are in there.
A:

Thanks in advance,

Pavel Tsekov,
9000 Bulgaria, Varna,
LogSys BG


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.