-->
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 load, modify and save a collection?
PostPosted: Sun Jan 15, 2006 12:21 pm 
Newbie

Joined: Sun Jan 15, 2006 11:51 am
Posts: 8
It is too stupid but I cannot figure out how to load, modify and save a collection.

Exmple:
Code:
ITransaction transaction = session.BeginTransaction();
IList foos = session.CreateQuery("from foo").List(); // foos is just an ArryList,
                                                     // not a persistent collection!
foos.Add(new Foo());
session.SaveOrUpdate(foos);
transaction.Commit();

Remarks:
1. Collection (foos) in the real application changed not by me, but by data binding, so I do not know what has been changed, thus I do not want to save each Foo instance individually.

2. Collection (foos) does not mapped as propery (or field) of any class, but I can map it to class with name Registry for example, but this class must be static (or a singleton) and it does not persist in any database table at all, so it has no id.

Can anybody tell how to save modifyed collection or make mapping of it as a property of a not persistent class (without id).

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 4:36 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
(vb code but should be no problem converting into c#)
<code>
for each foo as Foo in foos
session.saveOrUpdate(foo)
next
</code>

_________________
michal


Top
 Profile  
 
 Post subject: Не не
PostPosted: Tue Jan 17, 2006 4:55 am 
Newbie

Joined: Sun Jan 15, 2006 11:51 am
Posts: 8
Не не, foreach? What about deleting an item?
Code:
foos.RemoveAt(0);
foreach (Foo foo in foos)
{
     session.Delete... // Нmm how to delete???
}

Thanks, I thought so and first decided to make a clone of collection and compare two collections in order to remove deleted items but finally I implemented IBindingList and IEditableObject to handle each item individually.


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.