Abhishek Purwar,
Bangalore.
Paul Sturrock wrote:Why do you need to lock the table to do what you are doing? And why do they need to be "in one go"?
Abhishek Purwar,
Bangalore.
Abhishek Purwar wrote:Hi all,
I need suggestion regarding an issue.
I want to execute multiple statements on a table
at one go in order but i don't want to use stored procedure.
For e.g.
LOCK TABLE nested_category WRITE;
SELECT @myRight := rgt FROM nested_category
WHERE name = 'TELEVISIONS';
UPDATE nested_category SET rgt = rgt + 2 WHERE rgt > @myRight;
UPDATE nested_category SET lft = lft + 2 WHERE lft > @myRight;
INSERT INTO nested_category(name, lft, rgt) VALUES('GAME CONSOLES', @myRight + 1, @myRight + 2);
UNLOCK TABLES;
I want to execute this statement using HibernateTemplate.
Can any one suggest me how to proceed???
Thanks to all for their suggestion.
Abhishek Purwar,
Bangalore.
Abhishek Purwar wrote:@Paul and Eduardo
Can you guys suggest me how should i achieve my requirement using transaction with hibernatetemplate???
Paul Sturrock wrote:In this order:
Start a transaction Do your reads, updates and inserts Commit or rollback your transaction depending on success
Abhishek Purwar,
Bangalore.
Abhishek Purwar,
Bangalore.
Abhishek Purwar,
Bangalore.
But rolled back is not working because changes done by update statement is present in database table.
Paul Sturrock wrote:
But rolled back is not working because changes done by update statement is present in database table.
In which case you are not running in a transaction, or your rollback statement is not being run.
Abhishek Purwar,
Bangalore.
Abhishek Purwar wrote:
Paul Sturrock wrote:
But rolled back is not working because changes done by update statement is present in database table.
In which case you are not running in a transaction, or your rollback statement is not being run.
Hey Paul,
If error occurs during some transaction for e.g. if any statement fails then i want to roll back the transaction.
In the code snippet, if you see there is an IF-ELSE block. Intentionally , i am forcing my transaction to throw error and if error comes then it goes to catch block.
In catch block, i am rolling back the transaction but when i check database table, i observed that changes made by UPDATE statement is there.
I want the table to show data which is before UPDATE statement.
Abhishek Purwar,
Bangalore.
Abhishek Purwar wrote:Rollback is not working due to DB engine.
In MySQL, MYISAM engine does not support transaction and thats why rollback is not working.
After changing it to InnoDB, it is working fine.
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|