-->
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.  [ 5 posts ] 
Author Message
 Post subject: Help needed: flush updates all the fields of the entity
PostPosted: Wed Apr 02, 2008 8:42 am 
Newbie

Joined: Tue May 22, 2007 10:52 am
Posts: 13
If I update one field of the entity in java code (using the setter), when I do fludh(), hibernate updates all the columns for that entity (even though I did not modify them).

(This is a big problem since I have 2 pages that modify different fields of the same entity, that can be accessed concurrently by 2 users.)

Is this the default behavior of hibernate?? It seems buggy to me.

Thanks,


Top
 Profile  
 
 Post subject: Re: Help needed: flush updates all the fields of the entity
PostPosted: Wed Apr 02, 2008 8:56 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
You can enable dynamic-updates on an entity and hibernate will only update its modified properties. However, fetching and updating dynamic-update enabled entities should happen with the same session.


Farzad-


Top
 Profile  
 
 Post subject: problems with dirty check, use a timestamp per field?
PostPosted: Thu Apr 03, 2008 5:39 am 
Newbie

Joined: Thu Sep 20, 2007 7:06 am
Posts: 2
Hi,
I have a problem with the following scenario.
The bean B has three fields, B.x , B.y, B.z

time t1
I detach an instance (B1) of B and it has the following values:
B.x = B.x_old
B.y = B.y_old
B.y = B.z_old

time t2
I modify the instance B1 doing B.x = B.x_new

time t3
Another process dows an update on B doing B.y = B.y_new and commits

time t4
I attach the instance B1 and, with dynamic-update=true and select-for-update=true, Hibernate checks dirty and commits the following data:
B.x = B.x_old (WRONG!!)
B.y = B.y_new (CORRECT)
no update on B.z (CORRECT)

The problem is that, when checking for dirty, it seems that hibernate checks ONLY the timestamp of the entire entity, NOT the timestamp of single fields. So, If I have a detached instance with OLD data and I modify ONLY a field and in the meanwhile another process does an update on ANOTHER field, when I commit changes I loose this last modification.

Is there a way to use a sort of timestamp for every field the compose an entity? Does hibernate supports this or it's a specific problem ?

thanks a lot


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 03, 2008 7:02 am 
Newbie

Joined: Wed Mar 28, 2007 1:05 am
Posts: 8
Hi,

What i have understood from your explanation is that you have more than one detached object of the class B and what you want is to keep those in synch with DB which is conceptually wrong. You process should share the same copy of B so that any update done my multiple processes should be on the same Object whose state can be flushed to DB.

Cheers
Deepak


Top
 Profile  
 
 Post subject: timestamp for fields
PostPosted: Fri Apr 04, 2008 11:59 am 
Newbie

Joined: Thu Sep 20, 2007 7:06 am
Posts: 2
Hi Deepak,
thanks for your reply.
The problem is this:
I'm trying to do an update ONLY on a subset of fields, but what I get is that, although using dynamic-update and select-for-update techniques, if ANOTHER field has changed and has a more recent value than the one in my detached entity, I override its value.

Let me try to explain it better

entity with fields a,b,c,d,e

- I read the entity and detach it
- Another process modifies and commit field "e"
- On my detached entity, I change field a,b, reattach the entity and the dynamic update creates an update on a,b,e

Note that MY field "e" is OLD, so I loose the changement the external process has done.

In standard SQL I'd have been
UPDATE entity, set a='XX', b='YY'


what's your opinion about?


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