-->
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.  [ 4 posts ] 
Author Message
 Post subject: mass update
PostPosted: Wed May 09, 2007 3:27 am 
Beginner
Beginner

Joined: Wed May 02, 2007 12:24 am
Posts: 41
Hello,

I have a method where I get an array of primary keys and I need to update the status of the associated reocrds.

Now I know this isn't OO, but the network cost is too much to send a list of objects to the server just to get thier status updated.

Is there a way I can achieve this in nHibernate?

One thing that has occured to me is after I get the list of primary keys load the objects from the db (using nhibernate) change status and then save them one by one...

I'm not sure if it is the right thing to do.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 3:40 am 
Newbie

Joined: Thu May 03, 2007 2:30 am
Posts: 18
Hello..

Even if you are using NHibernate, you still have the option to use "plain" SQL to accomplish batch updates. This will allow you for greater flexibility. There is no need to go "pure OO" in your Project. If you identified a "Problem" like this, then you can safely fall back to using direct SQL or Stored proceures.

I know this will cause some people to say this is not "OO" or not the right way to use NHibernate, but NHibernate offers you the option, and you decide how to do what you need to acomplish.

And now to soothe the minds of the NHibernate "purists"... You can still construct a very lightweight object, which will only carry the information that you need for this usecase (ID + statusID) and use this to perform the operations... But I would still prefer way #1


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 4:06 pm 
Beginner
Beginner

Joined: Wed May 02, 2007 12:24 am
Posts: 41
Thanks,

I'm going to try it second way, for now: by modeling a lightweight type.

Regards.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 4:11 am 
Newbie

Joined: Thu May 03, 2007 2:30 am
Posts: 18
h1 wrote:
Thanks,

I'm going to try it second way, for now: by modeling a lightweight type.

Regards.


Hello...

I dont know what size of array you are talking about, but even if you use lightweight objects, NHibernate would generate a single update querry for each object. If the array is big, or the operation is done often by many users you might consider the 1st aproach. (The reason here is that it "might" cause a lock escalation in sql sever)


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