-->
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.  [ 7 posts ] 
Author Message
 Post subject: NHibernate + WinForms Apps = Design Question
PostPosted: Mon May 22, 2006 12:39 pm 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
Hi!

I'm developing WebForms apps that use NHibernate to persist my objects. I'd like to know how do you transport (carry) your interface data to the NHibernate methods. (please, I'd like solutions in a Master/Detail scenario)

For example, I have two fields: Id and Name. When I click "Save", I create an XXX object, set the properties (id and name) and call XXX.Save(my object).

But when I have a list of items, how do you keep it in memory before save? I was thinking to use DataSets ... how do you do?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 1:14 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
i think you mean "collection" when talking about "list." if so, you have a couple of options depending upon how you associate (map) your objects.

If you have a Master -> Detail like so:

Code:
<bag name="Details" inverse=true cascade="all-delete-orphan">
    ...
</bag>


and a Detail -> Master like so:

Code:
<many-to-one name="Master" class="Master" />


you have several options one of the easiest being save your master object first, then create detail objects, adding them to your Master.Details collection, then persist Master

Code:
Master myMaster = new Master();
...
session.Save(myMaster);

Detail myDetail = new Detail();
...

master.Details.Add(myDetail);
myDetail.Master = myMaster

session.SaveOrUpdate(myMaster);


because cascade is set, the new Detail objects will be persisted.

just one way of doing it but it really depends on your internal code...


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 1:20 pm 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
The problem is here:

Code:
Detail myDetail = new Detail();
...

master.Details.Add(myDetail);


where do you keep your data to load into the myDetail object? Could you complete the "..."? :)

I've been used datasets ... I save my items into a dataSet, move them to myDetail objects, add them to the Master and Save the master.

Do you use datasets too?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 9:02 am 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
What do you think about use datasets in the interface and when the user clicks Save button I move the data from the DataSet to DAO objects?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 11:43 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
sorry for the delay in responding...

i'm not really sure why you would create "datasets" and not objects (or a collection of objects) and pass then to your DAOs. why do you feel you need to use a "dataset?"


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 4:45 pm 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
devonl wrote:
sorry for the delay in responding...

i'm not really sure why you would create "datasets" and not objects (or a collection of objects) and pass then to your DAOs. why do you feel you need to use a "dataset?"


Hello Devonl!

I'm thinking to use DataSets junt in the interface layer to keep the data in memory before save them. I don't know how to use collections. Is it possible? Simple? :)

My app has three layers:

- Interface
- Logic
- NHibernate

Has any other way to do a master/detail without datasets? Using collections is difficult?

My Logic layer just work with Objects. So, in my interface I move the records from dataSets to objects/collections and then I call the Logic Layer. For example, the button Save:

// load the master (any object)
...

// load the details
List<Person> p = new List<Person>();

foreach (PersonRow row in DataSetPerson.Rows)
{
p.Add(new Person(row.Id, row.Name));
}

// save all
master.Save(...) // this will save the master and details

So, what do you thnik about it? Should I use another approach to move my data from interface to logic layer?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 9:45 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
that works fine. if you want to use datasets in your interface, then by all means. i don't see any problem with it. however, you wouldn't normally assign the ID to the person object; instead allowing the database to set the identity.

-devon


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