-->
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.  [ 2 posts ] 
Author Message
 Post subject: Does Nhibernate supports bulk saving ?
PostPosted: Thu Dec 13, 2007 5:27 am 
Newbie

Joined: Mon Jul 16, 2007 9:35 am
Posts: 17
Hi all,

I am currently working on NHibernate 1.2 for my Project.
I was able to save my transaction using save(caseObject) for Single Entity.If i try the same for entity collection save(caseObjectCollectionb), I am unable to achieve it.

The reason behind targeting this bulk insert, is to minimise the hit to the database.By getting support to bulk insert(say 5 or 15 records) the number of hits to the database is reduced to 1 rather than depending on the number of records.

Here with I have provided samples.

Normal Save Entity:

public virtual Result Save(Case objCase)
{
try
{
this.OpenSession();
this.BeginTransaction();
session.Save(objCase);

this.CommitTransaction();
return new Result(true);
}
catch (Exception ex)
{
return new Result(false,ApplicationManager.StackExceptionMessages(ex),ex);
}
finally
{
}
}

Saving an EntityCollection:

public virtual Result Save(CaseCollection objCaseCollection)
{
try
{
this.OpenSession();
this.BeginTransaction();

session.Save((IList)objCaseCollection);

this.CommitTransaction();
return new Result(true);
}
catch (Exception ex)
{
this.RollbackTransaction();
return new Result(false, ApplicationManager.StackExceptionMessages(ex), ex);
}
finally
{
}
}

When i try to save this EntityCollection, I am getting this ERROR
"Unknon Entity Class".


Please give me your thoughts, what i am missing or wrong.
Let me know any further clarification needed.

Thanks
Cheers
Sudhagar.S


Top
 Profile  
 
 Post subject: Re: Does Nhibernate supports bulk saving ?
PostPosted: Thu Dec 13, 2007 4:35 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
I've never heard of this being supported, and the error you got would appear to indicate that it isn't. That is, that "CaseCollection" is not a mapped class.

Even if it were, it would be no more efficient than you iterating over the collection yourself:

Code:
public virtual Result Save(CaseCollection objCaseCollection)
        {
            try
            {
                this.OpenSession();
                this.BeginTransaction();
               
                foreach ( object o in objCaseCollection ) session.Save(o);

                this.CommitTransaction();
                return new Result(true);
            }
            catch (Exception ex)
            {
                this.RollbackTransaction();
                return new Result(false, ApplicationManager.StackExceptionMessages(ex), ex);
            }
            finally
            {
            }
        }


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

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.