This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate update when Object isn't modified Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate update when Object isn Watch "Hibernate update when Object isn New topic
Author

Hibernate update when Object isn't modified

RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528

Hi Ranchers

Hibernate will not issue update statement when called update() when the object is not modified.
Means that when you don’t want to perform an update on an object , if the object isn’t modified .

Is this behaviour default or do i need to set any parameters for this ??

Please Help.

If you want something you never had do something which you had never done
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Is this behaviour default or do i need to set any parameters for this ??

No, It's not default but you can ask hibernate to behave like that explicitly by setting dynamic-update=true. This is a class level attribute.
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Are you sure it is with explicitly by setting dynamic-update=true

Because when i had gone through docs it said you need to set optimistic-lock attribute to dirty .

Anybody help to add a light on this topic please.
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
RaviNada Kiran wrote:Are you sure it is with explicitly by setting dynamic-update=true

Did you try it?
RaviNada Kiran wrote:Because when i had gone through docs it said you need to set optimistic-lock attribute to dirty
Again did you try this?
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
The dynamic-update would be fine updating the individual columns and optimistic lock code for the whole Object .
aran tam
Greenhorn

Joined: Jun 24, 2009
Posts: 12
hi, everybody:
i came cross this problem too! anyone has a good idea to solve it?
BTW, i use Struts2+Spring2+Hibernate3.
Spring takes charge of the Struts Action(scope="prototype") and Hibernate session/transaction.

I tried this: dynamic-update="true", but the setting is useless.

i've been seeking for long and got one solution:
load an object before you update it. (it means if you wanna modify an object, you'll have to load it for two times, and then saveOrUpdate it at last)...but i think it's not that good. Especially, we have to set all the properties by hand....oh, god. .what if the object is big enough as the earth?

i've been looking for a better way for 2 days...what makes me confused, what does the property "dynamic-update" use for???...

pardon my poor english..

best regards.

A reply from asia...
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Especially, we have to set all the properties by hand....oh, god. .what if the object is big enough as the earth?

Doesn't loading it before updating fix this? Why do you need to set properties by hand? Just set those you are updating.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
aran tam
Greenhorn

Joined: Jun 24, 2009
Posts: 12
Paul Sturrock wrote:

Especially, we have to set all the properties by hand....oh, god. .what if the object is big enough as the earth?

Doesn't loading it before updating fix this? Why do you need to set properties by hand? Just set those you are updating.

hi, Paul.
i use getHibernateTemplae().load(XXX.class, id) to load an object, then modify it in a form, and submit.
the property scope="prototype" in applicationContext.xml.
saveOrUpdate(obj). If there is not hidden property "id" in the form, "save(obj)" would be called. If there is a hidden property "id", "update(obj)" would be called, but those properties didn't need to change and i didn't modified is null....
so i have to load the object once again and set all the properties by hand, cuz i just need to modify some properties in different situation.

i am sorry for my poor english , i just can't express it out, though it might be just a very simple problem.
anyways, thank you, Paul
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hibernate update when Object isn't modified