-->
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: Handling new objects and assigning an id
PostPosted: Tue Apr 25, 2006 4:43 pm 
Newbie

Joined: Mon Apr 03, 2006 5:12 pm
Posts: 15
Location: Glasgow, Scotland
I wonder if anyone has this situation when using NHibernate in a WinForms app.

I have a screen that contains a grid of a number of objects, say Customers. The user can click on a customer and edit the details and so on. I handle the grid events by storing the id of a customer in a hidden column so I know which one the user has clicked on.

This is fine for existing customers but if I create a number of new customers I cannot differentiate between them as they all have the "unsaved-value" as their Id. I get around this by assigning a unique negative number to the Id within the screen and using this to identify the customer selected in the grid. I then reset all negative ids back to the unsaved-value before commiting them to the database. I am not sure this is the best method though. Has anyone else come across this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 9:26 pm 
Regular
Regular

Joined: Fri Jul 29, 2005 9:46 am
Posts: 101
Hi!

Quote:
I have a screen that contains a grid of a number of objects, say Customers. The user can click on a customer and edit the details and so on. I handle the grid events by storing the id of a customer in a hidden column so I know which one the user has clicked on.


You do not need the id of a customer in WindowForms.NET (you can get a direct reference to you object using "bindingSource.Current" in .NET 2.0
( http://www.windowsforms.net/Samples/Go% ... %20FAQ.doc ) or
BindingContext[objectView].Current in .NET 1.x ( http://msdn.microsoft.com/library/defau ... 122002.asp )


Now... in ASP.NET you do not have "direct databinding to in memory objects" so your idea of using negative ids could be useful... (I have seen it implemented in the DataSet... and in other ORMs for example Apple's EOF or EntityBroker) in my experience most Java Hibernate users commit things to the database on every request... seems to be the recommended way of doing things... or at least Hibernate does not seem to provide help to do something else... and I guess that is what most ASP.NET NHibernate users do (I have done it that way)... I would be nice to know what is the recommended practice to avoid commiting to the database on every request....


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.