• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

How can i synchronize table data?

Dear Experts,

I have a table called EMPLOYEE, suppose if two employees are trying to update the same filed data in that table. how can i avoid this?  
0
haneef_nb
Asked:
haneef_nb
  • 2
  • 2
  • 2
  • +2
1 Solution
 
Dejan PažinHead of SW DevelopmentCommented:
0
 
CEHJCommented:
Is this a Java q or an Oracle one?
0
 
Dejan PažinHead of SW DevelopmentCommented:

If for example you are using Hibernate, you can have optimistic locking auto implemented for you by version attribute on the entity:

Each time before a change is submited to the database the version attribute is checked and if it is not the in the database as on the entity, then someone has changed the content and the transaction will not be commited. You will have to read the entity again and then save it (and the sam procedure will occure). Once the change is approved, the version attribute is increased.

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Sathish David Kumar NArchitectCommented:
@ CEHJ

Say correct you can do it in 2 ways !!

in oracle auto commit off then commit while your finish your job !!

0
 
slightwv (䄆 Netminder) Commented:
From an Oracle (or just about any RDBMS), you really don't need to worry about this. The first update will lock the row will get it. The second update will block until the lock is released.

You may have an application issue that you need to work out if two people update the same field about the same time, the 'locked' update is not aware of the previous commit. It might generate some bad data. ÿ 

You will need to control that at the application layer.
For example:
user1: update emp set salary=salary*10 where emp_id=1;
user2: update emp set salary=salary*10 where emp_id=1;
user1: commit;
user2: commit;

What is the 'new' salary for employee?
0
 
haneef_nbAuthor Commented:
Dear Experts,

i want in both ways, in Oracle & Java..

Please explain in brief in both the ways..
0
 
slightwv (䄆 Netminder) Commented:
There is no 'both' ways.  There is how the RDBMS handles row locking then how a the app makes the calls.

Oracle is the RDBMS and Java is the app layer making calls to the RDBMS.  They really aren't the same.
0
 
Sathish David Kumar NArchitectCommented:
in oracle auto commit off then commit while your finish your job !!
0
 
haneef_nbAuthor Commented:
Thanks..
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now