• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Hibernate - update specific field with unique id

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to fire query using Hibernate to update specific field. Here, I dont have object in the memory so, other fields will have null value.

If I try SaveOrUpdate() call then it will overwrite null values to other fields.

I can retrieve the object, populate it and then fire saveOrUpdate() but this looks me inefficient.

I can use SQL query but I am wondering if any better approach is available.

Please guide.

Thanks,
Bhavin
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I can use SQL query but I am wondering if any better approach is available.


Yes, you could use an HQL query, then your code is cross platform.
 
Bhavin Sanghani
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Other than cross platform thing, should we consider cost of loading object before updating it?

Thanks
Bhavin
[ December 09, 2008: Message edited by: Bhavin Sanghani ]
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably not. The best approach is normally to prototype your functionality and performance test it, if this is a concern. My guess is its probably not that bad.
 
author
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another approach is to use bulk queries in HQL

insert ... select ...
update ...
delete ...

which will update the data using an SQL query wo having to load the objects.

check the Hibernate reference documentation for more info
 
Bhavin Sanghani
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think, with this approach it would be a problem if you are logging all the actions (INSERT, UPDATE, DELETE) in the database. You may have to write separate logic to log actual transaction..isn't it?
 
Emmanuel Bernard
author
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe, it depends what you mean by logging and how you do it. But it's true that object lifecycle is not called.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You may have to write separate logic to log actual transaction..isn't it?


Do you mean seperate to the database's own transaction log?
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic