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: Save/Delete object without loading from Session first
PostPosted: Thu Jul 13, 2006 6:42 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Hi,

I am using an ObjectDataSource with a GridView in ASP.NET 2.0 and letting the ODS automatically update and delete the object by setting the UpdateMethod and DeleteMethod properties along with the DataObjectTypeName property.

So, my service layer has 2 methods like below:

Code:
public static void Update(Customer customer)

public static void Delete(Customer customer)


It appears that when I update an object via the GridView, a Customer object is being instantiated and then all the properties are being set (including the key) before my Update method is called. The session must look at the key and know what to do with this object because it is being updated correctly in the DB.

When an object is being deleted via the GridView, a Customer object is being instantiated and just the key property is being set before my Delete method is called. Again, the session is able to deal with this and delete the object from the DB.

Is it safe to let it operate this way or should the object really be loaded via the session first before Session.Update or Session.Delete are called?

Thanks,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 14, 2006 7:34 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
It should work fine except for delete - it won't be able to handle cascades and might cause problems with optimistic versioning. It's probably better to use something like session.Delete(session.Load(typeof(Entity), obj));


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 1:54 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Thanks Sergey. Will add this safeguard to the Delete.


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.