Forums Register Login

Hibernate - update specific field with unique id

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 


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.
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
Maybe, it depends what you mean by logging and how you do it. But it's true that object lifecycle is not called.
+Pie Number of slices to send: Send
 


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?
He baked a muffin that stole my car! And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3667 times.
Similar Threads
Questions about LAZY and EAGER loading (JPA 1.0)
Getting incorrect values from SQL query
Hibernate Identifier and primitive types
Hibernate - saveOrUpdate = insert or update?
when we update in hibernate will it always fire select query before updating
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:26:17.