-->
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.  [ 26 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Wed Sep 17, 2003 12:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I seem to remember Gavin mentioning that he may/has implemented something similiar, but if I remember correctly it was every column. It was meant more as a type of locking strategy.

I believe you could possibly do this using a custom EntityPersister subclass. Specifically, look at overriding the EntityPersister.update() method.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 17, 2003 12:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yeah, its in CVS.


Top
 Profile  
 
 Post subject: Modified Column
PostPosted: Wed Sep 17, 2003 3:16 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 6:44 pm
Posts: 20
Great!
This way we won't face last Update vanishing problem.

Ashok


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 17, 2003 8:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I'd suggest being very careful using this, or at least being aware of some potential issues. Especially if you either 1) use Oracle, or 2) use DB triggers and attempt to persist an entity a second time within the same session.

With triggers, say you create a new entity using Session.save(). The DB trigger then dynamically replaces some column value, but the entity object cached in Session does not know about this. Later on the same session you try to update that same entity instance. This extended where clause will now fail to find the record due to the mismatch.

With ORacle, the issue is much more insidious. Oracle has this wonderful "feature" where all empty values (i.e., zero-length strings) for varchar columns are replaced with null during insert/update statements. Unfortunately, it does not do the same thing on select statements. So the following:
Code:
INSERT INTO company (id,name) VALUES (1, '');
SELECT * FROM company WHERE name = '';

will fail to find the just inserted record.

Just FYI...


Top
 Profile  
 
 Post subject: Update Modified columns
PostPosted: Fri Sep 19, 2003 9:55 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 6:44 pm
Posts: 20
Hi steve,
Yes we are using oracle ,thanks for pointing out that issue.
I have one more question.
If hibernate is going go include all the columns in where clause then i am seeing a probelm here.
for e.g
Two user are trying to modify the same record belongs to one employee.One user trying to modify salary and other user trying to modify the department.if they try to update the record at the same time then only one update will sucess and other will fail.

Update table set salary = new sal where id = originalid and salary = oldsalary and department = olddepartment.

Second user:
Update table set department = new department where id = originalid and salary = oldsalary and department = olddepartment.

Hope the example is clear.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2003 4:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Thats why I mentioned it was intended for locking previously.

You really are talking about two different things.

Quote:
This way we won't face last Update vanishing problem.

This is the purpose of locking or versioning your data. Simple locks based on only the changed columns are to simplistic most of the time. For example, say you have a table which holds a column "check_number", 'po_number', and 'payment_method'. User 1 modifies an existing record to update the 'check_number' field as the check has been received from the customer. User 2 modifies the same record to update the 'payment_method' to 'PO' and set the 'po_number', all by mistake. Simple column-based locking will not detect this situation. And even though you have lost no data because it is all seperate columns, the lock did not work. Use a version column or a timestamp column to acheive this much more effectively.


Top
 Profile  
 
 Post subject: Interceptor.findDirty
PostPosted: Fri Sep 19, 2003 6:32 pm 
Beginner
Beginner

Joined: Fri Aug 29, 2003 12:38 am
Posts: 22
Location: Phoenix, AZ
I am suprised the altenative solution was not proposed.

If you need to use dynamic updates, but are updating in a different session than the load, you could use your own dirty determination (perhaps dirty flags in the object) and write an Interceptor that implements findDirty(). Then your findDirty() would simply need to check your dirty flags and return the dirty properties.

(warning - I have not actually run a code test against this.. yet)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2003 10:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
I am suprised the altenative solution was not proposed


Probably because findDirty() in-and-of itself will not constrain the update statement to only changed values. You still need to enable dynamic-update for that to occur.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 20, 2003 12:43 am 
Beginner
Beginner

Joined: Fri Aug 29, 2003 12:38 am
Posts: 22
Location: Phoenix, AZ
Quote:
Probably because findDirty() in-and-of itself will not constrain the update statement to only changed values. You still need to enable dynamic-update for that to occur.


Ah, but the original poster was originally asking about this in conjunction with dynamic-update enabled, so I was assuming dynamic-update enabled.

So the combination of a findDirty interceptor combined with dynamic-update=true should give the effect needed, even if the object is loaded in one session and saved in another.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 20, 2003 4:20 pm 
Newbie

Joined: Tue Aug 26, 2003 9:45 am
Posts: 17
Location: Toronto, Canada
steve wrote:
I'd suggest being very careful using this, or at least being aware of some potential issues. Especially if you either 1) use Oracle, or 2) use DB triggers and attempt to persist an entity a second time within the same session.

...

With ORacle, the issue is much more insidious. Oracle has this wonderful "feature" where all empty values (i.e., zero-length strings) for varchar columns are replaced with null during insert/update statements. Unfortunately, it does not do the same thing on select statements. So the following:
Code:
INSERT INTO company (id,name) VALUES (1, '');
SELECT * FROM company WHERE name = '';

will fail to find the just inserted record.

Just FYI...


If Hibernate itself is aware of this behaviour (in Oracle), it should be able to work around it. I have used the MVCSoft persistence manager (EJB CMP 2.0 implementation) in the past, and it does do this form of update, and properly handles this issue.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 21, 2003 9:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
If Hibernate itself is aware of this behaviour (in Oracle), it should be able to work around it. I have used the MVCSoft persistence manager (EJB CMP 2.0 implementation) in the past, and it does do this form of update, and properly handles this issue.


I insist that Oracle should fix this bug, not Hibernate ;)

It is trivial to write a Hibernate usertype to work around this problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 26 posts ]  Go to page Previous  1, 2

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.