Thanks again
Just in case I've missunderstood. Do you mean that changing my master
entity to HiLo will affect the time i takes to save one Master and all
its details? Doesn't that just affect the time it takes to save
several masterEntities? This is not a problem in this scenario. I will
never save more than one MasterEntity at a time.
Instead what bewilders me is that if I save one (only one) master
entity with all its details by calling Session.Save(masterEntity) it
takes 2 minutes 30 seconds.
If I instead change cascade of the set mapping to none and then do:
Session.Save(masterEntity)
//then call save on every single detailEntity
foreach (var detail in masterEntity.Details)
{
Session.Save(detail)
}
it only takes 24 seconds instead of over 2 minutes.
So in this case it is not the performance of NHibernate doing mass
updates that is poor. (24 seconds is sufficient, but 2 min 30 seconds
is not).
Rather that it does not perform if I do
Session.Save(masterEntity).instead of Save on each detailEntity.
On 1 Maj, 21:10, Jason Meckley <[email protected]> wrote:
> it's a combination of the two. because you are using an identity POID
> you will not be able to preform batch operations on this entity.
> However the children use hilo which can be batched. Because of this
> the infrastructure design will influence the domain. you could to
> this:
> foreach(var parent in parents)
> {
> session.Save(parent);}
>
> foreach(var parent in parents)
> {
> parent.Add(child);}
>
> saving the parents will not be batched... it's just not possible. but
> the children at then added after the save and would all be committed
> when the session is flushed. The children would then be batched (I
> think).
>
> There are some other things to consider.
> 1. change the parent entity to use hilo instead of identity. It more
> work to migrate the database to the new application, but it will pay
> off in the long run.
> 2. if this is a bulk upload operation consider using an alternative
> solution. NH is not meant for bulk operations. It *can* support them,
> but it's not the best use of NH out of the box. I really like
> Rhino.ETL for bulk operations.
>
> On May 1, 9:35 am, robcar <[email protected]> wrote:
>
>
>
>
>
> > Hello and thanks for the answer.
>
> > I do use identity for my master (PriceChangeCase) but I do not use it
> > for my details (PriceChange). So batching do work, it is only that
> > saving the collection of PriceChanges by them selves is soooooo much
> > faster than saving them together with the root aggregate
> > (PriceChangeCase) (using cascade for the set mapping in the mapping of
> > my master).
>
> > So the question really is if this is by design or if I am doing
> > something else that is wrong?
>
> > On 1 Maj, 00:01, Jason Meckley <[email protected]> wrote:
>
> > > you are using identity (a database POID generator) which cannot take
> > > advantage of batching. Only the client POID generators (hilo and guid)
> > > can take advantage of batched inserts. this is due to the nature of
> > > how/when an id is assigned to an entity and how the UOW operates with
> > > client vs database POIDs. if you google NHibernate POID you will find
> > > 2 posts by Fabio on the topic.
>
> > > On Apr 30, 3:52 pm, robcar <[email protected]> wrote:
>
> > > > I am quite new to NHibernate and might be doing things wrong but am
> > > > facing a problem with my current mapping setup and performance when
> > > > saving.
>
> > > > I have enabled batch-size <property name="adonet.batch_size">100</
> > > > property>) and then I save my root aggregate and cascade my them from
> > > > my master to my set of detail rows.
>
> > > > The problem occurs when saving. Saving 5000 master entities with one
> > > > detail row each (total of 10000 objects) takes 2 min 30 seconds.
> > > > If I instead save all my 5000 master entities by them selves and then
> > > > all my 5000 detail rows by them selves, it takes some 24 seconds.
>
> > > > Is this by design or am I doing something nasty and wrong?
>
> > > > My mapping looks like this:
>
> > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> > > > assembly="Entities" namespace="Entities">
> > > > <class name="PriceChangeCase" table="[PriceChangeCase]">
>
> > > > <id name="PriceChangeCaseId" column="PriceChangeCaseId"
> > > > type="System.Int32" unsaved-value="0">
> > > > <generator class="identity"/>
> > > > </id>
> > > > <property name="EffectiveDate" column="EffectiveDate" not-
> > > > null="true" type="System.DateTime" insert="true" update="true"/>
> > > > <property name="Name" column="PriceChangeCaseName" not-null="true"
> > > > type="System.String" insert="true" update="true"/>
> > > > <many-to-one name="Currency" class="Currency" fetch="select" not-
> > > > null="true" outer-join="auto" insert="true" update="true"
> > > > unique="true">
> > > > <column name="CurrencyId"/>
> > > > </many-to-one>
> > > > <many-to-one name="Owner" class="Buyer" fetch="select" not-
> > > > null="true" outer-join="auto" insert="true" update="true"
> > > > unique="true">
> > > > <column name="BuyerId"/>
> > > > </many-to-one>
> > > > <set name="PriceChanges" inverse="true" cascade="all-delete-
> > > > orphan" lazy="true" fetch="subselect" generic="true">
> > > > <key>
> > > > <column name="PriceChangeCaseId" not-null="true" />
> > > > </key>
> > > > <one-to-many class="PriceChange" />
> > > > </set>
> > > > <property name="Status" column="PriceChangeCaseStatusId" not-
> > > > null="true" insert="true" update="true"/>
> > > > <property name="Comment" column="Comment" not-null="false"
> > > > type="System.String" insert="true" update="true"/>
> > > > </class>
> > > > </hibernate-mapping>
>
> > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> > > > assembly="Entities" namespace="Entities">
> > > > <class name="PriceChange" table="[PriceChange]">
>
> > > > <id name="PriceChangeId" column="PriceChangeId"
> > > > type="System.Int64" unsaved-value="0">
> > > > <generator class="hilo"/>
> > > > </id>
> > > > <many-to-one name="PriceChangeCase" column="PriceChangeCaseId" not-
> > > > null="true"/>
> > > > <many-to-one name="Price" lazy="proxy" cascade="none"
> > > > class="Price" fetch="select" not-null="true" outer-join="auto"
> > > > insert="true" update="true" unique="true">
> > > > <column name="PriceId"/>
> > > > </many-to-one>
> > > > </class>
> > > > </hibernate-mapping>
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "nhusers" group.
> > > > To post to this group, send email to [email protected].
> > > > To unsubscribe from this group, send email to
> > > > [email protected].
> > > > For more options, visit this group
> > > > athttp://groups.google.com/group/nhusers?hl=en.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "nhusers" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected].
> > > For more options, visit this group
> > > athttp://groups.google.com/group/nhusers?hl=en.-Dölj citerad text -
>
> > > - Visa citerad text -
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group
> > athttp://groups.google.com/group/nhusers?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group
> athttp://groups.google.com/group/nhusers?hl=en.- Dölj citerad text -
>
> - Visa citerad text -
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.