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.  [ 6 posts ] 
Author Message
 Post subject: nhibernate web applications parent child relations
PostPosted: Sat Feb 24, 2007 9:01 am 
Newbie

Joined: Sat Feb 24, 2007 8:40 am
Posts: 4
Hello, I would like to know how child-parent relations are best implemented in a web application.

Suppose you following scenario on a web page:

A form containing information about the parent

A gridview displaying all children

A formview to view, edit, insert a child.

How do you implement this with nHibernate ?

Suppose you want to delete a child. Typically, the Gridview will give you the ID of the child.

When the page postbacks, I don't have a reference to the Parent object anymore, as web applications are stateless . Do I need to do a sesion.Load for the Parent? Will all Children need to be retrieved (as I have to find the Child object in the Childeren list of the parent?).

Does anyone have a full example web application of a Parent Child relationship with add,delete,update of child records?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 26, 2007 10:22 am 
Newbie

Joined: Mon Jul 18, 2005 7:45 am
Posts: 16
In a web application you should have a Session-per-request (usually implemented as HttpModule) Therefore, you will need to reload any object that is used on postback.

That doesn't necessary mean that you have to reload everything on postback though, since the form, grid view etc. will be populated from the viewstate by default.

You will need to reload any object(s) that may have changed though - e.g. if you add a child object you will need to load the parent and then rebind the grid.

It is also possible to detach and re-attach objects, storing them in e.g. session state between requests, though I've not had any experience doing this. I know that doing this has implications for lazy loading behaviour though.

This is a good 'best practice' article for NHibernate with web apps.

http://www.codeproject.com/aspnet/NHibernateBestPractices.asp


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 8:30 am 
Newbie

Joined: Sat Feb 24, 2007 8:40 am
Posts: 4
I've read that article and used a lot of the ideas there. However, all examples are always very basic, never show more complex web applications... My questions only begin where all the articles stop. Relations, gridview/formview examples, databinding with objectdatesource, data validation.

I guess others too are still looking for answers.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 9:16 am 
Regular
Regular

Joined: Sun Jan 21, 2007 4:33 pm
Posts: 65
rekna wrote:
I've read that article and used a lot of the ideas there. However, all examples are always very basic, never show more complex web applications... My questions only begin where all the articles stop. Relations, gridview/formview examples, databinding with objectdatesource, data validation.

I guess others too are still looking for answers.


Three of your areas are outside of the scope of ORM, as far as I can tell -- If you want to know about Relations when it comes to web forms, your best bet is to scour the online library at ora.com (Called Safari) and look for a book on web forms (most likely ASP.NET, though they have books on PHP, Perl CGI, et. al.) With data validation, there's no need to bring ORM into that -- data validation is just a pure code thing -- depending on the language, www.ora.com once again has the answer in their 'cookbook' series -- and you'll probably find the answer (with code) to your issues there.

As far as Databinding goes -- that's mostly your normal databinding code, simply with ORM handling the gory details about pulling that stuff out of a database. In C#, its accomplished with a foreach loop, as with some other languages (I believe PHP has it, and if not, I know Perl does).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 11:04 am 
Newbie

Joined: Wed May 02, 2007 12:56 pm
Posts: 17
Hello

I´m using the following code for the sesion. Each request is created the schema. My only problem is that how can i maintened sessión between several reuest. that is: I will have a page with a datagrid. The dategrid will have all the children from a parent, and you can edit them and when you are really sure you save all the changes to database. How can i do that? I´m starting to get crazy.

Borja


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 4:04 pm 
Newbie

Joined: Wed May 02, 2007 12:56 pm
Posts: 17
I found this. I try to solve my problems.
http://www.flux88.com/AccessingSessionF ... odule.aspx


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