-->
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: simple update of one column based on PK
PostPosted: Sat Jul 24, 2004 2:07 am 
Newbie

Joined: Sat Jul 24, 2004 1:53 am
Posts: 4
Hi

i have just started using hibernate and am currently migrating an application to it. naturally there are many issues which with the help of the doc (excellent btw!!) and this forum's search, i'm getting through it.

i am using hibernate v2.4.1 with postgresql v7.4.2. i have't posted my code or mapping doc as this is a 'generic' case.

one thing i haven't been able to figure out is doing a simple update of one column for multiple rows as in the following:

UPDATE table_name SET status = 0 WHERE id_value IN (1, 2, 3)

it seems to me that i can only do the above with an update on each individual object (or collection of them). this means that each column is being updated when i only want one column changed in addition to needing complete values for all columns - ie. my objects have been retrieved in full and all fields populated.

in the above case i have only the id and the new value for that column. i don't see why i should need to retrieve all those objects just to update one column. this adds uneccessary overhead to the process (??). to put it in some context, the above arises within a page of checkboxes where their respective values is the id. selection of a (for example) 'disable' button changes the status of the selected values. using plain jdbc i would just create the above statement with the values of the id i needed to update. and thats it.

anyway, i'm a little stumped here. at the same time i may be missing the point in attempting to replace all my jdbc calls with hibernate. perhaps i should use it purely for object mapping (???) and rely on my existing jdbc calls for the 'funnies'.

any suggestions on the above using hibernate would be appreaciated.

Thanks

Takis


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 24, 2004 8:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
There is no other possiblitiy then loading the objects and modifying them. Hibernate is not made for mass operations.


Top
 Profile  
 
 Post subject: Re: simple update of one column based on PK
PostPosted: Sat Jul 24, 2004 11:25 am 
Beginner
Beginner

Joined: Wed Jul 21, 2004 12:28 pm
Posts: 27
Location: New York
takisd wrote:
perhaps i should use it purely for object mapping (???) and rely on my existing jdbc calls for the 'funnies'.


that is it. Think a bit logically here: you have a database, which is flat (3D space - field, record and relation). You as a developer want soemthing more manageable (not neccesarily less complex) objects (this is about 5D space - you add inheritance and polymorphism and a whole buch of other stuff, so it might be even more than 5D). Hibernate will help translate between the two, but it all costs something; no surprise here.

Now some operations are meant to be in 3D space, while others for the sake of manageability and ease of use/reuse, and ease of expansion better be in 5D. So it is up to you what you want to leave in 5D and what you want in 5D. Hibernate is just a link. Remeber back in the days you studied linear algebra, guess what, you thought you were studying the shit you will never need :-). Well it comes back to haunt you here! If you rember how clamsy that equation for a plane was in 3D spaces, and how nice and simple and yet mysterious it was in N-Space, he he the same is true here.

Your confusion is very much familiar to me; I have a lot of arguments with my boss, who refuses to get off the stored procedures. He motivates it with, well they can do everything. This statement is of course true, until we need to move from database A to database B (well that is a business decision, not a technical one) and all of his 1000 procedures that were developed in the course of 4-5 years are invalid overnight. While majority of theese procedures do not do more than a simple select, there are maybe a handfull that do usefull stuff that I would never even think of getting rid of; Like procedures that need to lock 50,000 records do calculation and do addition of a new record or deletion of old one, based on the result of the calculation. If I start mapping those 50K recs into 4D space ... well that will just be stupid. So use your own judgement and try to understand the use of ORM in general, what it bring to your plate and waht it takes away from it. Once you do the rest is easy, just use the strong features of both worlds to your own advantage and your programs will be as agile as they can possibly be :-) while satisfying your business requirements.

HTH,
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 26, 2004 2:52 am 
Newbie

Joined: Sat Jul 24, 2004 1:53 am
Posts: 4
Hi folks

thanks so much for your response.

that does it for me then... this really was quite a dilemma!!

i'll use hibernate for orm (as intended) and any funnies through plain old jdbc calls as previously.

your explanations were fantastic.

thanks heaps.

Takis


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.