-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to save list<T>
PostPosted: Wed May 30, 2007 4:29 am 
Newbie

Joined: Thu Mar 29, 2007 9:39 am
Posts: 10
hello,

how can i use SaveOrUpdate with a generic list<T> ?
Do i must use a for each, and save each object separately ?
What is the best method to save a list<T> ?

thanks
Decco


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 10:02 am 
Beginner
Beginner

Joined: Wed Jul 19, 2006 8:24 am
Posts: 35
Unless I'm missing something you'll have to use a for each.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 10:52 am 
Newbie

Joined: Thu May 31, 2007 5:14 am
Posts: 2
I think that the reason that he wants to save a list is that he expects the operation to be in a transaction. If one of the items in the list fail then none should be saved.

You cannot do that but you can easily create a helper method:

Code:
public static class Helper
{
      public static void SaveList(ISession session, IList list)
      {
            session.Transaction.Begin();
            foreach(object o in list) session.Save(o);
            session.Transaction.Commit();
      }
}

ISession session;
IList myList;
...
Helper.SaveList(session, myList);


Or is you have .net 3.0 via extension methods:

Code:
public static class Helper
{
      public static void SaveList(this ISession session, IList list)
      {
            session.Transaction.Begin();
            foreach(object o in list) session.Save(o);
            session.Transaction.Commit();
      }
}

ISession session;
IList myList;
...
session.SaveList(myList);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.