select for update doesn't lock the record with Base.OpenTransaction

65 views
Skip to first unread message

jye...@gmail.com

unread,
Jun 19, 2015, 8:28:24 PM6/19/15
to activejd...@googlegroups.com
I have to add the statement of Base.exec("start transaction") to get the select for update locking work as expected. Does Base.openTransaction() perform sql's start transaction? 

Why does the code below doesn't lock the record select without adding Base.exec("start transaction")?

Is it a known issue in ActiveJDBC?


try {
Base.openTransaction();
Base.exec("start transaction");
List<Map> res = Base.findAll("select 1 from example_table where table_id = 1");
Logger.info("get the lock: " + res);
Base.commitTransaction();
Logger.info("done commit");
} catch (Exception e) {
e.printStackTrace();
Base.rollbackTransaction();
throw e;
}

Julia

unread,
Jun 19, 2015, 8:32:39 PM6/19/15
to activejd...@googlegroups.com

Correct the typo in the code:

List<Map> res = Base.findAll("select 1 from example_table where table_id = 1 for update");

Igor Polevoy

unread,
Jun 21, 2015, 10:02:00 PM6/21/15
to activejd...@googlegroups.com
Julia, this code has nothing to do with record locking. These are simple convenience methods that start/commit  and rollback transactions. 




tx

Igor Polevoy

unread,
Jun 21, 2015, 10:02:29 PM6/21/15
to activejd...@googlegroups.com
you might also want to read this: 

tx
Reply all
Reply to author
Forward
0 new messages