-->
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: saving complex object tree optimalization
PostPosted: Mon Aug 30, 2010 8:14 am 
Newbie

Joined: Mon Aug 30, 2010 7:48 am
Posts: 1
Hi, I am currently working on a project that uses NH, FluentNH and Linq2NH. Everything works just fine but I wonder if there is any possibility to improve saving complex object's. I feel that saving objects as it is listed below is not the best practice and cause some performance issues:
Code:
        public override void SaveChanges(Member entity)
        {
            SessionProvider.GlobalSession.Evict(entity);

            using (ISession session = SessionProvider.SessionFactory.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    foreach (var charge in entity.Charges)
                        session.SaveOrUpdate(charge);

                    foreach (var invoice in entity.Invoices)
                        session.SaveOrUpdate(invoice);

                    session.Update(entity.ContactInformation);
                    session.Update(entity.MemberData);
                    session.Merge(entity);
                    transaction.Commit();
                }
            }

            SessionProvider.GlobalSession.Update(entity);
        }


Please tell me if there is any way of mapping that could cause the member object to be fully saved like this:
Code:
        public virtual void SaveChanges(T entity)
        {
            SessionProvider.GlobalSession.Evict(entity);

            using (ISession session = SessionProvider.SessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Update(entity);
                transaction.Commit();
            }

            SessionProvider.GlobalSession.Update(entity);
        }


I intentionally do not show mappings, relations etc. just want to know if it is common for NH to save objects like in first code block.
And regardless of the first answer - how to optimize that ;-)

Regards,


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.